...

View Full Version : mail() woes



chump2877
02-20-2008, 01:20 AM
I'm trying to figure out why the following code doesn;t send an email:



// Mail password.
$body = "Dear $firstname: \n\nYou are receiving this e-mail because you have requested a copy of your YourCompany.com username and password.\n\n \tUsername: ".$username."\n \tNew Password: ".$new_pass."\n\nAfter you log in with your new password, you may change your password to something else. \n\nThank you! \n\n - Staff";
$subject = "YourCompany.com: Lost Password";
$headers = "From: Admin<admin@domain.com>\r\n";

// echo $email . "<br>";
// echo $subject . "<br>";
// echo $body . "<br>";
// echo $headers . "<br>";
// die();

if (mail($email, $subject, $body, $headers))
{
$errors .= '<br /><span>Your password has been e-mailed to you.</span>';
}
else
{
$errors .= '<br /><span>E-mail failed. Please contact Administrator for assistance.</span>';
}


The variables appear to print out correctly (when the code is uncommented), and currently the text "Your password has been e-mailed to you." prints out to the screen.

This is the phpinfo page (http://runandgetit.com/phpinfo.php).

I've tried different variations of the "From:" header, and substituted variables in mail() with simple strings. Nothing seems to work with that code.

Interestingly, when I execute the following code in a file by itself:



<?
$headers = "From: Admin<admin@domain.com>\r\n";
mail("email@domain.com", "TEST", "THIS IS A TEST", $headers);
?>


The code seems to work -- sometimes.

I must be missing something somewhere. Can anyone help? If you need me to post more code, I can.

Thanks.

deamonlizard
02-20-2008, 01:28 AM
Try seperating the from name (Admin) and the email address, ie

Admin <admin@domain.com>

instead of

Admin<admin@domain.com>

Spamassasin blocks emails without spaces between the name and email address

chump2877
02-20-2008, 02:00 AM
Try seperating the from name (Admin) and the email address, ie

Admin <admin@domain.com>

instead of

Admin<admin@domain.com>

Spamassasin blocks emails without spaces between the name and email address

Thanks, that didn't seem to help though. Any other ideas?

rafiki
02-20-2008, 02:14 AM
change headers/subject?

chump2877
02-20-2008, 02:44 AM
change headers/subject?

The following code does not work:



<?
$headers = "From: Admin <admin@domain.com>\r\n";
mail("user@yahoo.com", "TEST1", "THIS IS TEST #1", $headers);
mail("user@yahoo.com", "TEST2", "THIS IS TEST #2");
?>

Neither e-mail is sent. God knows why.

_Aerospace_Eng_
02-20-2008, 02:51 AM
Who is your webhost? Many free hosts disable the smtp server.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum