Jump to content

Emailer not sending


kylenasa_star

Recommended Posts

Good afternoon,

I have a form that puts the info into a database and emails out the information. All is working great, except when the information contains the @ symbol for the email field, it doesn't email the information out. The entry in the database is fine, but I do not receive the email with all of the inputted information. All field are set in the html form as <input type="text".... and the fields are all varchar in the database.

I am new to php, and this may be ugly code, but any help on getting the emailer working would be appreciated!  The two things I noticed that make the emailer not work is less than 3 fields entered, and when an @ symbol is inputting, the later being a more important fix. See code below:

 

<?php
//include the connection file

require_once('connection.php');

//save the data on the DB and send the email

if(isset($_POST['action']) && $_POST['action'] == 'submitform')
{
//recieve the variables

$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];	
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$tour_date = $_POST['tour_date'];
$address = $_POST['address'];
$wine_type = $_POST['wine_type'];			
$favourite_winery = $_POST['favourite_winery'];	
$tour_before = $_POST['tour_before'];		
$location = $_POST['location'];
$overnight = $_POST['overnight'];			
$occasion = $_POST['occasion'];	
$veg_meals = $_POST['veg_meals'];								
$comments = $_POST['comments'];	
$ip = gethostbyname($_SERVER['REMOTE_ADDR']);

//save the data on the DB

mysql_select_db($database_connection, $connection);

$insert_query = sprintf("INSERT INTO contacts (first_name, last_name, email, telephone, tour_date, address, wine_type, favourite_winery, tour_before, location, overnight, occasion, veg_meals, comments, date, ip) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW(), %s)",
						sanitize($first_name, "text"),
						sanitize($last_name, "text"),							
						sanitize($email, "text"),
						sanitize($telephone, "text"),
						sanitize($tourdate, "text"),	
						sanitize($address, "text"),	
						sanitize($wine_type, "text"),									
						sanitize($favourite_winery, "text"),
						sanitize($tour_before, "text"),	
						sanitize($location, "text"),
						sanitize($overnight, "text"),															
						sanitize($occasion, "text"),	
						sanitize($veg_meals, "text"),																																																								
						sanitize($comments, "text"),
						sanitize($ip, "text"));

$result = mysql_query($insert_query, $connection) or die(mysql_error());

if($result)
{
	//send the email

	$to = "[email protected]";
	$subject = "Booking Request";

	//headers and subject
	$headers  = "MIME-Version: 1.0\r\n";
	$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
	$headers .= "From: ".$first_name." <".$email.">\r\n";

	$body = "Online booking request<br />";
	$body .= "First name: ".$first_name."<br />";
	$body .= "Last name: ".$last_name."<br />";		
	$body .= "Email: ".$email."<br />";
	$body .= "Telephone: ".$telephone."<br />";		
	$body .= "Tour date: ".$tour_date."<br />";	
	$body .= "Address: ".$address."<br />";
	$body .= "Preferred wine type: ".$wine_type."<br />";		
	$body .= "Favourite winery: ".$favourite_winery."<br />";
	$body .= "Been on a previous tour: ".$tour_before."<br />";	
	$body .= "Location of previous tour: ".$location."<br />";		
	$body .= "Overnight accommodations: ".$overnight."<br />";				
	$body .= "Occasions: ".$occasion."<br />";
	$body .= "Number of vegetarian meals: ".$veg_meals."<br />";																
	$body .= "Specific requests: ".$comments."<br />";
	$body .= "IP: ".$ip."<br />";

	mail($to, $subject, $body, $headers);

	//ok message

}
}

function sanitize($value, $type) 
{
  $value = (!get_magic_quotes_gpc()) ? addslashes($value) : $value;

  switch ($type) {
    case "text":
      $value = ($value != "") ? "'" . $value . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $value = ($value != "") ? intval($value) : "NULL";
      break;
    case "double":
      $value = ($value != "") ? "'" . doubleval($value) . "'" : "NULL";
      break;
    case "date":
      $value = ($value != "") ? "'" . $value . "'" : "NULL";
      break;
  }
  
  return $value;
}
?>

 

Thanks a bunch!

Kyle

 

 

Link to comment
https://forums.phpfreaks.com/topic/165964-emailer-not-sending/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.