Outgoing Mail address with PHP?

Hi, I have a website that sends out emails to users when they sign up to confirm their e-mail address using PHP’s mail(); function, but the address and name people are receiving from is like: “No from address/name specified” (bunch of numbers)@hostingaccount.com

I’ve specified a “from” address in the headers but it seems to have no affect.

Have I misconfigured something or do i need to upgrade to be able to spoof the “from” address and/or name? Honestly i don’t care what the address is (and i’m not willing to pay something like £50 a year for some email address linked to my domain…), it’s just the name “No from address/name specified” is pretty weird…

can i somehow link the email account i can make in the cpanel with the PHP mail(); function? or… is that seperate? or…

I’ve been trying to find a solution to this all night so I’ve given up and am hoping you could shed some light on best practices on this sort of thing or what i’m doing wrong…

Thanks in advance for any help you can provide! I appreciate it!

As long as the header is defined correctly, the from address should be picked up properly. So it could be something’s broken on our end.

Are you using some kind of off-the-shelf software I can try for myself and/or a minimal example with which you get the issue so I can test stuff without having to use your account?

Hi admin, thanks for your swift response, considering you said it should be working, i tried several different headers but now i’m just getting the feeling that the emails are getting caught up in infinity free’s automated spam filter and aren’t even sending out, so i can’t test the headers anymore (i even reverted the code to the original state and it’s not sending emails at all now.)

The code that worked (but gave me the “No from address/name specified” (bunch of numbers)@hostingaccount.com address) is this:

$mailMsg = "Thank you for registering at Canvas Penguins! Please follow this link to activate your account: http://canvaspenguins.com/?p=veri2&u=$regUser&vc=$emailVeri"; $mailHeaders = 'From: [email protected]' . "\\r\ " . Reply-To: [email protected]' . "\\r\ " . X-Mailer: PHP/' . phpversion(); mail($regEmail,"Canvas Penguins - Account Verification",$mailMsg, $mailHeaders);

I tried these but did not recieve any emails:
$mailto = $regEmail; $mailsubject = "Canvas Penguins - Account Verification"; $mailmessage = "Thank you for registering at Canvas Penguins! Please follow this link to activate your account. http://canvaspenguins.com/?p=veri2&u=$regUser&vc=$emailVeri"; $mailheader = "From: [email protected] < [email protected] >\ "; $mailheader .= "Cc: [email protected] < [email protected] >\ "; $mailheader .= "X-Sender: [email protected] < [email protected] >\ "; $headers .= "X-Mailer: PHP/".phpversion()."\\r\ " $mailheader .= "X-Priority: 1\ "; // Urgent message! $mailheader .= "Return-Path: [email protected]\ "; // Return path for errors $mailheader .= "MIME-Version: 1.0\\r\ "; $mailheader .= "Content-Type: text/html; charset=iso-8859-1\ ";

mail($mailto, $mailsubject, $mailmessage, $mailheader);

(and)

$mailto = $regEmail; $mailsubject = "Canvas Penguins - Account Verification"; $mailmessage = "Thank you for registering at Canvas Penguins! Please follow this link to activate your account. http://canvaspenguins.com/?p=veri2&u=$regUser&vc=$emailVeri"; $mailheader = ''; $mailheader = 'MIME-Version: 1.0'.PHP_EOL; $mailheader .= 'Content-type: text/html; charset=iso-8859-1'.PHP_EOL; $mailheader .= 'From: [email protected]<From: [email protected]>'.PHP_EOL;

mail($mailto, $mailsubject, $mailmessage, $mailheader);

Not really sure what to do about this… it works fine on my test environment for all three of these variants.

I just tested your script and I think I found the issue.

You see, the PHP mail() filters we use require that a correct, complete and valid From header is present. A correct sender address could be From: Canvas Penguins <[email protected]>. You need to specify both the name and the address for the email to be sent properly.

Your second and third versions don’t work because the email addresses are not valid. The email part must be like <[email protected]>. No spaces, no text, no special characters. Only then will the e-mail be sent properly.

Admin, you’re a legend, m8. That was exactly the problem and it works perfectly now, thanks! =D