Jump to content

Problem with PHP Mail From Name


pets2soul

Recommended Posts

Hello! Dear all,

 

I'm having this problem with PHP Mail From Name, it took me entire day, and still haven't figure out the issue...that is...

 

In "From: ", if I have it in simple email format, such as "From: name@server.com" it works...but when I have it with a From Name, eg. "From: Name <name@server.com>", then it just wouldn't send...

 

I heard that some of the servers just won't parse "Name <name@server.com>", if it is the case...would there be any work around to get that From Name appeared?

 

The code is attached below, any help is deeply appreciated!

 

<?php
//For Captcha
include("settings.php");
header("Content-Type: text/html; charset=utf-8");
@session_start();
$string = strtoupper($_SESSION['string']);
$userstring = strtoupper($_POST['userstring']); 
@session_destroy(); 
if (($string != $userstring) || (strlen($string) <= 4)) {
header("location:contact_us.php");
exit();
}

//PHP Mail starts here
$form_name = $_POST["name"];
$form_company = $_POST["company"];
$form_email = $_POST["email"];
$form_phone = $_POST["phone"];
$form_mobile = $_POST["mobile"];
$form_msg = $_POST["msg"];
$form_date = date(Y)."-".date(m)."-".date(d);
$form_ip = $_SERVER["REMOTE_ADDR"];
$form_lang = "en";

$fromname = "Name";
$frommail = "name@server.com";

@require("../default_timezone.php");

$con = mysql_connect("host","user","pass");
mysql_query("SET NAMES 'utf8'");
if (!$con)
{
die("Could not connect: " . mysql_error());
}
mysql_select_db("dbname", $con);
mysql_query("INSERT INTO tablename (CU_Name, CU_Company, CU_Email, CU_Tel, CU_Mobile, CU_Content, CU_CreateDate, CU_IP, lang)
VALUES ('$form_name', '$form_company', '$form_email', '$form_phone', '$form_mobile', '$form_msg', '$form_date', '$form_ip', '$form_lang')");

	$message = ("
	<table width=\"500\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\">
	<tr>
	<td colspan=\"2\" align=\"left\"><img src=\"contact_logo.gif\" /></td>
	</tr>
	<tr>
	<td colspan=\"2\" align=\"left\"><font style=\"font-size: 12px; color: #000;\">Your email is recceived, a representative will be contacting you soon.</font></td>
	</tr>
	<tr>
	<td width=\"70\" align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Name:</b></font></td>
	<td width=\"430\" align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_name}</font></td>
	</tr>
	<tr>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Company:</b></font></td>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_company}</font></td>
	</tr>
	<tr>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Email:</b></font></td>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_email}</font></td>
	</tr>
	<tr>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Phone:</b></font></td>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_phone}</font></td>
	</tr>
	<tr>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\"><b>Mobile:</b></font></td>
	<td align=\"left\"><font style=\"font-size: 12px; color: #000;\">{$form_mobile}</font></td>
	</tr>
	<tr>
	<td align=\"left\" valign=\"top\"><font style=\"font-size: 12px; color: #000;\"><b>Message:</b></font></td>
	<td align=\"left\" valign=\"top\"><font style=\"font-size: 12px; color: #000;\">{$form_msg}</font></td>
	</tr>
	</table>
	");

$subject = "Email Subject";
$mime_boundary = md5(uniqid(mt_rand(), TRUE));
$header = "From: ".$fromname." <".$frommail.">\r\n";
$header.= "To: " . $to . "\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: multipart/mixed; \r\n";
$header.= " boundary=". $mime_boundary . "\r\n";
  
$content = "This is a multi-part message in MIME format.\r\n";
$content .= "--" . $mime_boundary . "\r\n";
$content .= "Content-Type: text/html; charset=utf-8\r\n";
$content .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
$content .= $message. "\r\n";

$to=$form_email;
@mail($to, $subject, $content, $header);
$to2="my@server.com";
@mail($to2, $subject, $content, $header);

echo "<html>";
echo "<head>";
echo "<META HTTP-EQUIV='Content-Type'  content='text/html; charset=utf-8'>";
echo "<META HTTP-EQUIV='Refresh' CONTENT='3; URL=http://www.server.com/'>";
echo "</head>";
echo "<body>";
echo "Thank you for contacting us!";
echo "<br />";
echo "Your message is sent.";
echo "</body>";
echo "</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.