Forum Moderators: coopster

Message Too Old, No Replies

Making "From:" include address AND name of sender

         

hairycoo

10:39 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



I'm installing a newsletter script and I've been racking my brains trying to make it work.

I have this bit of code

if (!isset($err)) {
// send confirmation email
$headers = 'From: '.$cfg['from'];

if ($cfg['headers']) {
foreach ($cfg['headers'] as $val) $headers .= "\n".$val;
}
$headers .= "\n".$cfg['header_plain'];
if (!@mail($cfg['fromname'], $addr, $cfg['subj_conf'], sprintf($cfg['msg_conf'], '?type=confirm&email='.urlencode($addr)), $headers)) {
$err = 'There was an error sending the confirmation email. Please try again later.';
}
}

I want the From field to include the sender's name (predefined as $cfg['fromname']) as well as address. I've searched the net but could only find this

$headers .= "From: \"".$fromname."\" <".$fromaddress.">\n";

Unfortunately, the above makes optional headers (Mime-Version and Content-Transfer-Encoding: 8bit) get included in the email body!

If anyone can help I'd appreciate it. I'm a complete noob at PHP

jatar_k

10:50 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try with out the extra set of double quotes and the extra space

$headers .= "From: ".$fromname."<".$fromaddress.">\n";

hairycoo

11:04 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



Tried it just now. Doesn't work, it gives me "Error: There was an error sending the confirmation email. Please try again later". Is there any way to do this manually? e.g. without calling the php variables?

jatar_k

11:10 pm on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



mail($cfg['fromname'], $addr, $cfg['subj_conf'], sprintf($cfg['msg_conf'], '?type=confirm&email='.urlencode($addr)), $headers)

you have too many parameters there and the $headers variable is in the wrong place.

[php.net...]