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.

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. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.