0

this is my code so far

function send_email() {

$email = $_POST['signup-email'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];

$to = "[email protected]";
$subject = "Email from
RateMyLife.com"; $body = "Hi ,$firstname $lastname, this is an email from RateMyLife.com"; $headers = "From:[email protected]";

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($insertSignup){ //if insert is successful
       send_email();
    }

the email is not send...

thanks i cant figure out what is the problem.

4
  • does this work? in a file with nothing else: mail('your_email_address', 'test', 'test'); Commented Feb 23, 2011 at 19:05
  • are you getting any error messages? Commented Feb 23, 2011 at 19:06
  • I recommend you using the PHPMailer class or any other option instead of the simple mail() function. Commented Feb 23, 2011 at 19:53
  • This code is vulnerable to sql injection. Commented Feb 23, 2011 at 22:26

2 Answers 2

2

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('[email protected]', 'My Subject', 'test message');
Sign up to request clarification or add additional context in comments.

1 Comment

didn't know about swiftmailer. Being from Fabien Potencier (the guy behind the Symfony framework) must be good. Thanks for the comment @AlfaTeK
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.