I created a form with a processing PHP file. Everything works fine. I receive the mail but it's from "Unknow sender" in Gmail. Why please ?
I would like to see in my email box the name and the firstname of the person who fills the form. What's wrong in my code ?
<?php
if(isset($_POST) && isset($_POST['form3_firstname']) && isset($_POST['form3_name']) && isset($_POST['form3_email']) && isset($_POST['form3_telephone']) && isset($_POST['form3_message'])) {
extract($_POST);
if(!empty($form3_firstname) && !empty($form3_name) && !empty($form3_email) && !empty($form3_telephone) && !empty($form3_message)) {
$to = 'XXXXXX#gmail.com'; // My real email
$subject = 'Contact from the site';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\r\n";
$headers .= 'Reply-To:'.$form3_email. "\r\n";
$message = '<html><body>';
$message .= '<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>';
$message .= '<table>';
$message .= '<tr><td colspan="2"><p>MESSAGE</p></td></tr>';
$message .= '<tr><td>Firstname :</td><td>'.$form3_firstname.'</td></tr>';
$message .= '<tr><td>Name :</td><td>'.$form3_name.'</td></tr>';
$message .= '<tr><td>Email :</td><td>'.$form3_email.'</td></tr>';
$message .= '<tr><td>Telephone :</td><td>'.$form3_telephone.'</td></tr>';
$message .= '<tr><td>Message :</td<td>'.stripslashes($form3_message).'</td></tr>';
$message .= '</table>';
$message .= '</body></html>';
if(mail($to, $subject, $message, $headers)){
echo "Form sent";
} else {
echo "Form not sent";
}
} else {
echo "You have not filled in the field";
}
}
?>
Replace the $form3_name with $form3_email
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\r\n";
^^^^^^^^^^^^ //<----- Here
That's a name , not an email address , and that's the reason you get that error.
Also, you need to wrap them in tags <>
The right way..
$headers .= 'From:' .$form3_firstname. " ".'<'.$form3_email.'>'."\r\n";
replace "\r\n" with "\n" and your problem will be solved... and also put return-path in your headers...
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
$headers .= 'From: \''.$form3_firstname.'\' <'.$form3_firstname.'>\r\nReturn-Path: <'.$form3_firstname.'>
$headers .= 'From:' .$form3_firstname. " " .$form3_name. "\n";
$headers .= 'Reply-To:'.$form3_email. "\n";
please let me know if you want furtther guidance...
Because you do not supply an emailaddress in your "From:" header. There always needs to be an emailaddress.
Try something like:
$headers .= "From: $form3_firstname $form3_name <$form_email>\r\n";
Mind you, you may have to test and/or escape your form variables; for instance, check that there is no newline in there, otherwise your form might be abused for spamming.
Related
I am using postfix to send an email to the user, but the problem is it breaks the words where it finds the space.
Here is the screenshot:
postfix-send-email
PHP code to send an email:
<?php
$subject = "Status Of mail";
$message = "Test Email using Postfix Apache2";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
$send = mail('test#yahoo.com', $subject, $message, $headers);
if($send)
{
return 1;
}
else
{
return 0;
}
?>
Try replacing
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
with
$headers .= "From: The Travel Worthy <pathik#gmail.com>\r\n";
I am trying to add my companies logo inside of a php email that I will be sending out to customers after they order. However, it is not working. The actual link to my image is a public url.
What am I doing wrong?
$logoImage = 'https://example.com/images/BFBlogo1.gif';
// Prepare the Email
$to = $email;
$subject = 'Your Example order'. $AuthorrizeResponseText; transaction Id or invoice #, however you set it up as.
$message = '<img src="'.$logoImage.'">';
$message = 'Thank you for ordering with us! ';
$from = "auto-confirm#example.com";
$cc = "order-receipts#example.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Cc: '.$cc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
My second attempt:
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';
You forgot to concate:
$message = '<img src="'.$logoImage.'">';
$message = 'Thank you for ordering with us! '; // here $message is overwrtting.
Should be like this:
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';
Update
logoImage = 'https://example.com/images/BFBlogo1.gif';
// Prepare the Email
$to = $email;
$subject = 'Your Example order'. $AuthorrizeResponseText;
$message = '<img src="'.$logoImage.'">';
$message .= 'Thank you for ordering with us! ';
$from = "auto-confirm#example.com";
$cc = "order-receipts#example.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
$headers .= 'Cc: '.$cc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
You set the image tag:
$message = '<img src="'.$logoImage.'">';
But then on the very next line you overwrite it:
$message = 'Thank you for ordering with us! ';
Maybe you meant to concatenate instead?:
$message .= 'Thank you for ordering with us! ';
Please note also that if nearly the entire body of the message is an image then I wouldn't be at all surprised if the mail is treated as spam by almost any system that looks at it.
I have this php mail() code on my site, which works fine.
It is an ecard system, my client can fill out the from info (name, email) and to info (name, email), etc and Mail goes straight to Inbox, on google, hotmail, yahoo, etc.
When the receiver gets the email he can use the reply button, and it gets the right info.
The problem is the From: header in my mail form, I want to change this from noreply#example.com to the receiver's info, or any other info. When I do that, the mail goes into SPAM mail.
Here is the code I'm using
<?php
$name = $_REQUEST['name'] ;
$motive = $_REQUEST['email'] ;
$name2 = $_REQUEST['name2'] ;
$email2 = $_REQUEST['email2'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;
$message = urldecode(stripslashes($message));
$headers = 'From:' . $name . ' John Q<noreply#example.com>' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.= "Reply-To:" .$name. "<" . $motive. ">\n";
$headers.= "Return-Path: My Company<admin#datatopixels.com>\n";
$headers.= "X-Mailer: PHP". phpversion() ."\n";
$messagee = "
<html>
<head>
<title>Title here</title>
</head>
<body>
<center>
<br>
</center>
</body>
</html>
";
mail($to, $subject, $messagee, $headers);
?>
You must to add a needle headers:
Sample code :
$headers = "From: myplace#example.com\r\n";
$headers .= "Reply-To: myplace2#example.com\r\n";
$headers .= "Return-Path: myplace#example.com\r\n";
$headers .= "CC: sombodyelse#example.com\r\n";
$headers .= "BCC: hidden#example.com\r\n";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
And I would suggest to read oswalds's
I have problem with non english characters with this e-mail script. If I set the script to send e-mail to my gmail account, I have no problem. However, if I set the script to send email to my domain account and if i open the email with windows live mail or with microsoft outlook then the e-mail is not readable. I must to go to encoding menu, and then select the utf-8, and then i can read the email.
If I open the mail on iMac mail client, i have no problem.
My customer see this as big problem and want me to solve it. Anyone can help?
Here is the code:
<?php
// send the form to the specify email
// CONFIG VARS
$subject = "mysite.com | contact form";
$to = "myaccount#somemail.com";
$from = 'another#somemail.com';
//data
$msg = "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: <".$from. ">" ;
//send
mail($to, $subject, $msg, $headers);
?>
Any help will be deeply appreciated.
Zoran
Checkout this code it will work for me,
<?php
$subject = "mysite.com | contact form";
$to = "myaccount#somemail.com";
$from = 'another#somemail.com';
$msg = '<html>
<head>
</head>
<body>
<p>
Name: ".$_POST['namesup']."<br>
Email: ".$_POST['emailsup']."<br>
Phone: ".$_POST['phonesup']."<br>
Message: ".$_POST['yourtextsup']."<br>
</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= "From: <".$from. ">" ;
mail($to,$subject,$msg,$headers);
?>
This line $headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n"; is resolved your issue of like Arabic language or others.
I would suggest making sure your message is valid HTML, including the <html> and <head> tags, and also make sure you include the <meta http-equiv="Content-Type" content="text/html charset=UTF-8" /> tag. So:
//data
$msg = '<html><head><meta http-equiv="Content-Type" content="text/html charset=UTF-8" /></head><body>';
$msg .= "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
$msg .= '</body></html>';
Try changing your scripts charset to:
<?php
// send the form to the specify email
// CONFIG VARS
$subject = "mysite.com | contact form";
$to = "myaccount#somemail.com";
$from = 'another#somemail.com';
//data
$msg = "Name: " .$_POST['namesup'] ."<br>\n";
$msg .= "Email: " .$_POST['emailsup'] ."<br>\n";
$msg .= "Phone: " .$_POST['phonesup'] ."<br>\n";
$msg .= "Message: " .$_POST['yourtextsup'] ."<br>\n";
//Headers
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";
$headers .= "From: <".$from. ">" ;
//send
mail($to, $subject, $msg, $headers);
?>
I am using this script to send notificaitons to users friends. the problem is that all recepieints get to see who else got this email. How do i tweak the code so the emails still get sent to all but they can't see who else got it?
Code:
$sql = "SELECT STRAIGHT_JOIN DISTINCT email from
friend_email_ids WHERE my_id='$id'";
$result = mysql_query($sql);
$query = mysql_query($sql) or die ("Error: ".mysql_error());
if ($result == "")
{
echo "";
}
echo "";
$rows = mysql_num_rows($result);
$emails = array();
if($rows == 0)
{
print("");
}
elseif($rows > 0)
{
while($row = mysql_fetch_array($query))
array_push($emails, $row['email']);
{
$email = $row['email'];
print("");
}
}
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail(implode(",", $emails), "Subject: $subject",
$message, "$headers" );
echo "";
Just use BBC for all recipients:
Bcc: recipients get a copy of the email, but their email address is
automatically deleted at delivery. Nobody except you and the Bcc:
recipient will know that they got a copy, and their email address will
not be exposed.
-> http://email.about.com/od/emailmanagementtips/qt/How_to_Send_an_Email_to_Undisclosed_Recipients.htm
Use the additional_headers fields to add a BCC* address . See the manual
From the manual page:
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
the "birthdaycheck" email is hidden.
*(Blind Carbon Copy)
In you script it would become something like this:
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "From: $usermail\r\n";
////////////pay attention here
$headers .= "BCC: ".implode(",", $emails)."\r\n";
$to = "youremail#domain.com"; //the mail in the "TO", visible to all. there has to be 1.
////////////////////////
$subject = "$full_name added";
$message = "<html><body>";
$message .= "Hello, <br><br>$full_name posted someth<br><br>";
$message .= "<a href=www.domain.com/signup.php?t=&sign=>Click here.</a><br><br>";
$message .= "</body></html>";
mail($to, "Subject: $subject",
$message, "$headers" );
echo "";
Put the actual sending of messages in the loop. That way you will send the e-mail to each recipient individually instead of all at once.
From PHP.net you'll find that the Bcc feature of mail() is what you need to use.
Like zoy (for multiple peeps):
$headers .= 'Bcc: someone#example.com,someone2#example.com,someone3#example.com,someone4#example.com,' . "\r\n";
Happy Haxin!
_wryteowl