How To Send Contact Form Fields In Email

I have the contact form working however I would like for it to send more information than just the message that the visitor submits, such as name and phone number.

The Contact form is the one set up with the Yii installation. The form has a field for visitor name. I can get the visitor name and the visitor message to show in the body of the message I receive but then the ‘From’ email address and the ‘ReplyTo’ email address doesn’t show the visitor address but rather it shows a Nobody@mylocalserver.

I installed the ‘mailer’ extension and get the same results.

Would someone please give an example or point to an example of how to send all of the Contact form fields to show in the body of my received email?

UPDATE: Progress made but still need help!

I finally got the form field ‘name’ to show in the message of my received email with the form field ‘body’ as well as show the ‘name’ in the ‘ReplyTo’ and ‘From’ address. Whew! and YEA!

Following this post, using YUM, I learned how to set the body using a variable with an array.

BuT… The Phone Number will not show in my email, it is blank :(

On the model ContactForm, I set the public variable for the form field phone as you can see in the code below. I even tried adding $phone = $model->phone; to the controller code on the line above the $message… but that didn’t work either.

I checked the form view for typos but it was fine.

code from controller

	public function actionContact()


		$model=new ContactForm;






$message = strtr ('Site Contact Submission

Name: {name}

Phone: {phone}


{message}', array(

'{name}' => $model->name,

'{phone}' => $model->phone,

'{message}' => $model->body));

$mailer = Yii::createComponent('application.extensions.mailer.EMailer');

$mailer->Host = 'localhost';


$mailer->From = $model->email;



$mailer->FromName = $model->name;

$mailer->CharSet = 'UTF-8';

$mailer->Subject = $model->subject;

$mailer->Body = $message;


code from model

class ContactForm extends CFormModel


	public $name;

	public $phone;

	public $email;

	public $subject;

	public $body;

	public $verifyCode;

Would someone please help with adding the phone number to the email?

[color="#006400"]/* moved from feature requests to Yii 1.1 general discussion (main help forum) */[/color]

Do you have any sort of validation rule on the phone number? Because if you don’t, and you don’t mark it ‘safe’ it will not be part of the POST data and therefore unavailable.

Do you have debugging turned on? You should see a pink warning message in the stack trace if this is the case.

For more information read the guide and this wiki:

Thanks, dniznick!

No, I didn’t have rules for the phone field, but I do now.

The link was very helpful and my contact form email is working great now. :)

Thank you very much!