Jump to content

php Mail Function


Dubya008

Recommended Posts

I'm using the php mail function on some forms for our company website. There is reason to believe that they sometimes don't work. Is this a normal behavior for this? We've been "discussing" whether or not they work for about 2 - 3 days and in most instances they do.

 

However we've had 1 person fill them out and then we never received the emails.

 

I was wondering if some of the people that have worked with php for a longtime have ever had any experience with this type of thing happening.

Link to comment
Share on other sites

The most common reason why the mail() function would randomly not send emails would be if you are putting a user entered email address in as the From: email address and relaying restrictions on the sending mail server is preventing it from being sent or domain/server checking on the receiving mail server is preventing its reception. The second most common reason would be if content on a line exceeds 70 characters and/or does not contain proper newline characters.

 

Both of these problems can (sometimes mail servers are setup to NOT provide error feedback) result in php notice/warning errors.

 

Is error_reporting set to E_ALL and log_errors set to ON so that all php detected errors would be logged so that you would be getting information about any problems that php detects?

 

You could also log all relevant information for each form submission so that you have a record of what is occurring. See the error_log function.

Link to comment
Share on other sites

Thank you for your response. I believe that is exactly what we're doing: using the end-user's address to send the info to our specific address. I've pasted some code that we had from the website designer. Can you tell me if you think that is the reason why it wouldn't work.

 

 

define('kOptional', true);define('kMandatory', false);error_reporting(E_ERROR | E_WARNING | E_PARSE);ini_set('track_errors', true);function DoStripSlashes($fieldValue)  { if ( get_magic_quotes_gpc() ) {   if (is_array($fieldValue) ) {    return array_map('DoStripSlashes', $fieldValue);   } else {    return stripslashes($fieldValue);   } } else {   return $fieldValue; } }function FilterCChars($theString) {return preg_replace('/[\x00-\x1F]/', '', $theString);}function CheckEmail($email, $optional) {if ( (strlen($email) == 0) && ($optional === kOptional) ) {  return true;} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {  return true;} else {  return false;}}if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];} else {$clientIP = $_SERVER['REMOTE_ADDR'];}$FTGFname = DoStripSlashes( $_POST['Fname'] );$FTGLname = DoStripSlashes( $_POST['Lname'] );$FTGCompany = DoStripSlashes( $_POST['Company'] );$FTGEmail = DoStripSlashes( $_POST['Email'] );$FTGWebsite = DoStripSlashes( $_POST['Website'] );$FTGPhone = DoStripSlashes( $_POST['Phone'] );$FTGCity = DoStripSlashes( $_POST['City'] );$FTGState = DoStripSlashes( $_POST['State'] );$FTGPostal = DoStripSlashes( $_POST['Postal'] );$FTGCountry = DoStripSlashes( $_POST['Country'] );$FTGQes1 = DoStripSlashes( $_POST['Qes1'] );$FTGQes2 = DoStripSlashes( $_POST['Qes2'] );$FTGQes3 = DoStripSlashes( $_POST['Qes3'] );$FTGPage=DoStripSlashes( $_POST['page'] );$validationFailed = false;# Fields Validationsif (!CheckEmail($FTGEmail, kMandatory)) { $validationFailed = true; }# Redirect user to the error pageif ($validationFailed === true) {#header("Location: http://lynxfulfillment.com/index.html");echo "<script>location='{$_SERVER['HTTP_REFERER']}'</script>"; }if ( $validationFailed === false ) {# Email to Form Owner  $emailSubject = FilterCChars("Lynx Fulfillment Website");  $emailBody = "Fname : $FTGFname\n"  . "Lname : $FTGLname\n"  . "\n"  . "Company : $FTGCompany\n"  . "Email : $FTGEmail\n"  . "Website : $FTGWebsite\n"  . "Phone : $FTGPhone\n"  . "City : $FTGCity\n"  . "State : $FTGState\n"  . "Postal : $FTGPostal\n"  . "Country : $FTGCountry\n"  . "\n"  . "Qes1 : \n"  . "$FTGQes1\n"  . "\n"  . "Qes2 : \n"  . "$FTGQes2\n"  . "\n"  . "Qes3 : \n"  . "$FTGQes3\n"  . "Site Number : 1\n"  . "Page Used : $FTGPage\n"  . "IP: $clientip \n"  . "index.html";  $emailTo = 'Lynx <prandolph@lynxfulfillment.com>';     $emailFrom = FilterCChars("$FTGEmail");     $emailHeader = "From: $emailFrom\n"   . "MIME-Version: 1.0\n"   . "Content-type: text/plain; charset=\"ISO-8859-1\"\n"   . "Content-transfer-encoding: 7bit\n";     mail($emailTo, $emailSubject, $emailBody, $emailHeader);        # Redirect user to success pageheader("Location: http://www.lynxfulfillment.com/success.html");}?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.