954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mail function not working in the "From" of email

Can anyone help me with the mail function? The mail is sending with the code below:

//  Set up Email Parameters
    $from = "Condolence Submission";
    $subject = "Condolence";

// To send HTML mail, set the Content-type header. */
    $headers = 'MIME-Version: 1.0' . "\r\n" .
			'Content-type: text/html; charset=iso-8859-1' .  \r\n" .
                       'To: Tara <tmv105@gmail.com>' . "\r\n" .
                       'From: $from' . "\r\n" .
                       'Cc: greatfultobe@yahoo.com' . "\r\n" .
                       'Bcc: talong@netscape.com' . "\r\n" .
                       'X-Mailer: PHP/' . phpversion();
 
//  Send Email
mail($to,$subject,$message,$headers);


...but the "From" in the email is showing as "$from" and not the value I have assigned the variable. I tried do this for the "From"

'From: Condolence Submission' . "\r\n" .

and I get (unknown sender) in the "From" of my email.

tmv105
Newbie Poster
22 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

I actually figured it out. If I place an email address in the from, it works. I suppose that PHP mail() requires an email address here. Here is what I did:

//  Set up Email Parameters
    $from = $_POST['email'];
    $subject = "Condolence";
	 
	// To send HTML mail, set the Content-type header. */
	$headers = 'MIME-Version: 1.0' . "\r\n" .
				'Content-type: text/html; charset=iso-8859-1' . "\r\n" .

	/* additional headers */
	//$headers .= "To: Michael <diehlfhi@aol.com>, Tara <tmv105@gmail.com>\r\n";
	'To: Tara <tmv105@gmail.com>' . "\r\n" .
	//'From: condolence@deihl.com' . "\r\n" .
	'From:'. $from . "\r\n" .
	'Cc: greatfultobe@yahoo.com' . "\r\n" .
	'Bcc: talong@netscape.com' . "\r\n" .
	'X-Mailer: PHP/' . phpversion();
     
    //  Send Email
    mail($to,$subject,$message,$headers);


Both ways work...either hard coding an email into the "From" or filling the value in from a variable set from data on my form.

Thought that I would give an attempt of an explanation to any who might wanna know. :)

tmv105
Newbie Poster
22 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You