Forum Moderators: coopster

Message Too Old, No Replies

send mail question

         

Sub_Seven

12:04 am on Nov 9, 2010 (gmt 0)

10+ Year Member



Hello people, I have a question about send_mail

I have this code on an external file:


function send_mail($from,$to,$subject,$body)
{
$headers = '';
$headers .= "From: $from\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Date: " . date('r', time()) . "\n";

mail($to,$subject,$body,$headers);
}


and this code which completes the email sending upon registration:


send_mail('info@somewebsite.com',
$_POST['email'],
'Thank you for becoming a member',
'Your Username is: '.$username;
'<br />Your password is: '.$pass);


My problem is I can only get this code to send the username; I don't get the password sent...

Could anyone point me in the right direction? Thanks :)

Matthew1980

8:43 am on Nov 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi there Sub_seven,

send_mail('info@somewebsite.com', $_POST['email'],'Thank you for becoming a member',
'Your Username is: '.$username;'<br />Your password is: '.$pass);

It wouldn't send the pass as you are using invalid syntax here, error_reporting(E_ALL); would have altered you to this, try this version instead:

send_mail("info@somewebsite.com", strip_tags($_POST['email']), "Thank you for becoming a member",
"Your Username is:".$username."\n\r Your password is:".$pass."\n\r");

Within your function you could set it to return a bool so that you could call the function from within an if clause so that you could display a message to confirm either a successful send or fail, that is the idea of using a function - so that you can return data from it.

Also, try not to use $_POST vars unsanitised in this way, this has the potential to harm your system, I would also do a validation check on the email address there so that you can guarantee what your sending is the correct format.

Hope that makes sense.

Cheers,
MRb

Readie

12:53 pm on Nov 9, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should add the below header too:

$headers .= 'Content-Type: text/html; charset="iso-8859-1"' . "\r\n";

Really you should use multipart/alternative for backwards compatability, but enough people have mail software capable of reading HTML emails these days that you can get away with it if you're feeling lazy :)

Sub_Seven

8:13 pm on Nov 9, 2010 (gmt 0)

10+ Year Member



Awesome guys, it works great, thanks alot for the help :)