Jump to content



Photo
- - - - -

Mail() Not Working?

PHP email form

  • Please log in to reply
2 replies to this topic

#1 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 02 November 2012 - 05:54 PM

I am using this code for an email form processor:

<?PHP
//security function
function IsInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)');
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
	 } else {
return false;
	 }
}

//Get form entries
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$description = $_POST['job-description'];
$contact_method = $_POST['contact-method'];

//security
if(IsInjected($email)) {
echo "Bad email value!";
exit;
}

//Compose email
$email_from = <valid address>;
$email_subject = "TopPage Design form submission: quotes.html";
$email_body = "*** FORM SUBMISSION *** \n
name: " . $name . "\n
email: " . $email . "\n
phone: " . $phone . "\n
description: " . $description . "\n
contact method: " . $contact_method . "\n
*** END OF EMAIL ***";

//Send email
$to = <valid address>;
$headers = "From" . $email_from . "\r\n";
$headers .= "Reply-To:" . $email . "\r\n";

//send
mail($to, $email_subject, $email_body, $headers);
//success
echo("success.");
?>


But for some reason I don't receive the email, even though i get the success message. Am I doing something wrong?

EDIT:
solved, was a server side issue :)


#2 2072

2072

    Casio over god

  • Admin
  • PipPipPipPipPipPipPipPip
  • 1550 posts
  • Gender:Male
  • Location:Somewherebourg
  • Interests:Cinema, Programming, Music and a lot of thing...

  • Calculators:
    AFX2 ROM 1.02, CFX-9940GT+, FX-180P-Plus

Posted 03 November 2012 - 01:25 AM

You should test for the return value of mail() before echoing 'success'

#3 flyingfisch

flyingfisch

    Casio Maniac

  • Deputy
  • PipPipPipPipPipPipPipPip
  • 1891 posts
  • Gender:Male
  • Location:OH,USA
  • Interests:Aviation, Skiing, Programming, Mountain Biking.

  • Calculators:
    fx-9860GII
    fx-CG10 PRIZM

Posted 03 November 2012 - 01:31 AM

Oh, ok. thanks :)





Also tagged with one or more of these keywords: PHP, email form

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users