Reputation: 1759
I am using YiiMail extension to send mails.
I have used the default contact.php file as my view.
mycontroller--
public function SendMail()
{
//$subject = $_POST["subject"]; gives error on adding this line
mail('to-mailid',"some Subject","some Message",'$headers');
}
1) When I run this, mail is been sent to the id. It comes under spam folder with my system name as the sender. Where should I add the from address from which the mail should be sent?
2) A mail is received with subject and message that is written in the controller. I'm not getting any subject/message that I give in the field values. For this I have tried using the following in my SendMail() function
$subject = $_POST["subject"];
It then gives an undefined variable:$subject.
Upvotes: 1
Views: 5884
Reputation: 6297
not
mail('to-mailid',"some Subject","some Message",'$headers');
use
$headers="From: [email protected]\r\nReply-To: [email protected]";
mail('[email protected]', "some Subject", "some Message",$headers);
You will have to set your headers correctly. I used an example.
To solve the $_POST['subject'] issue, look again at your form code. If it is a Yii form, the usage is most probably something like, where the 'ContactForm will depend on your form settings.
$subject = $_POST['ContactForm]["subject"];
Upvotes: 1