php mail function problem
this is my code so far
function send_email() {
$email = $_POST['signup-email'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$to = "the1nz4ne@hotmail.com";
$subject = "Email from
RateMyLife.com"; $body = "Hi ,$firstname $lastname, this is an email from RateMyLife.com"; $headers = "From:info@iphoneappgmz.com";
mail($to, $subject, $body, $headers);
exit();
}
$existingSignup = mysql_query("SELECT * FROM signups WHERE signup_email_address='$email'");
if(mysql_num_rows($existingSignup) < 1){
$date = date('Y-m-d');
$time = date('H:i:s');
$password = md5($passwd);
$insertSignup = mysql_query("INSERT INTO signups (signup_email_address, signup_date, signup_time, firstname, lastname, password, year, day, month, gender) VALUES ('$email','$date','$time','$firstname', '$lastname', '$password', '$year', '$day', '$month', '$gender')");
if($insertSignu开发者_运维百科p){ //if insert is successful
send_email();
}
the email is not send...
thanks i cant figure out what is the problem.
There can be a multitude of reasons... Are you on windows or linux server?
Check phpinfo to see if sendmail is correctly configured (sendmail_path).
If it is correctly configured, check why emails is not being sent in your smtp server log messages, check this for more details: http://pt.php.net/manual/en/function.mail.php#101588
If you don't have the sendmail correctly configured, you can still use an account you have in some SMTP server to send your emails. For that you should use a PHP lib to facilitate your work, for example, check this: http://swiftmailer.org/
Also, test this php code to send yourself the email and see if it works:
mail('YOUREMAIL@EXAMPLE.com', 'My Subject', 'test message');
Did you check if your two queries succeeded?
$existingSignup = mysql_query(...) or die(mysql_error());
$insertSignup = mysql_query(...) or die(mysql_error());
if either fails, they return boolean FALSE. If the first fails, then mysql_num_rows()
will fail as it expects a mysql result handle, not a boolean. And if the second fails, then $insertSignup will be false and your if()
will never trigger.
精彩评论