Jump to content

Form not sending email


Go to solution Solved by ginerjm,

Recommended Posts

I have a form using php that is supposed to send me an email with the info, as well as redirect the user to "thanks.html." The user is redirected, but I do not receive an email. The form is at http://www.express1warehouse.com/thanks.html

Here is the php. Can anyone see any problems here?

<?php
/*
This first bit sets the email address that you want the form to be submitted to.
You will need to change this value to a valid email address that you can access.
*/
$webmaster_email = "sales@express1warehouse.com";

/*
This bit sets the URLs of the supporting pages.
If you change the names of any of the pages, you will need to change the values here.
*/
$feedback_page = "contact.html";
$error_page = "error_message.html";
$thankyou_page = "thanks.html";

/*
This next bit loads the form field data into variables.
If you add a form field, you will need to add it here.
*/
$contact_name = $_REQUEST['contact_name'] ;
$company_name = $_REQUEST['company_name'] ;
$phone = $_REQUEST['phone'] ;
$email = $_REQUEST['email'] ;
$website = $_REQUEST['website'] ;
$type_of_product = $_REQUEST['type_of_product'] ;
$number_of_skus = $_REQUEST['number_of_skus'] ;
$orders_per_month = $_REQUEST['orders_per_month'] ;
$units_per_order = $_REQUEST['units_per_order'] ;
$storage_details = $_REQUEST['storage_details'] ;
$ship_method = $_REQUEST['ship_method'] ;
$intl_ship_details = $_REQUEST['intl_ship_details'] ;
$inv_rec_details = $_REQUEST['inv_rec_details'] ;
$returned_inv_details = $_REQUEST['returned_inv_details'] ;
$pack_details = $_REQUEST['pack_details'] ;
$backorder_noninv_details = $_REQUEST['backorder_noninv_details'] ;
$order_integration_details = $_REQUEST['order_integration_details'] ;

/*
The following function checks for email injection.
Specifically, it checks for carriage returns - typically used by spammers to inject a CC list.
*/
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;
	}
}

// If the user tries to access this script directly, redirect them to the feedback form,
if (!isset($_REQUEST['email'])) {
header( "Location: $feedback_page" );
}

// If the form fields are empty, redirect to the error page.
elseif (empty($email) || empty($contact_name)) {
header( "Location: $error_page" );
}

// If email injection is detected, redirect to the error page.
elseif ( isInjected($email) ) {
header( "Location: $error_page" );
}

// If we passed all previous tests, send the email then redirect to the thank you page.
else {
mail( "$webmaster_email", "Request for Quote",
  $contact_name, $company_name, $phone, $email, $website, $type_of_product, $number_of_skus, $orders_per_month,
   $units_per_order, $storage_details, $ship_method, $intl_ship_details, $inv_rec_details, $returned_inv_details,
    $pack_details, $backorder_noninv_details, $order_integration_details, "From: $email" );
header( "Location: $thankyou_page" );
}
?>
Link to comment
https://forums.phpfreaks.com/topic/279265-form-not-sending-email/
Share on other sites

  • Solution

#1 - you don't check the result of your "mail" statement.  Why not?  It should return a False value since you have not followed the syntax of the "mail" function.

 

Per the php manual, the "to", "subject" & "message" args are to be followed with "headers" which must all be separated with a newline.  Also there is a requirement that one of the headers contain a From address.   Since you didn't begin with  the "from" address, the Mail function is probably not recognizing it all the way at the end of the long concatenated string of info that you are including.

 

Try doing this:

 

$mail_ok = mail(......);

if (!$mail_ok)

{

  echo "Could not send mail";

  exit();

}

header(.......);

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.