I am using a mail function to send html to an email address, but the From name and email address aren't showing up. This is my code:
$name = $_POST['name'];
$mailTo = 'name#email.com';
$subject = 'Message from ' . $_POST['name'];
$message =
'<html>
<head>
<title>HTML email</title>
</head>
<body>
<p><b>Name:</b> ' . $_POST['name'] . '</p>
<p><b>Email:</b> ' . $_POST['email'] . '</p>
<p><b>Message:</b> ' . $_POST['mainmessage'] . '</p>
</body>
</html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Postmaster <some#body.com>';
mail($mailTo, $subject, $message, $headers);
I would expect the email to show up as being from Postmaster at the email address some#body.com, but it is showing up as coming from ideapale#box486.bluehost.com, which is my hosting provider.
What did I not set up correctly?
Chris, try adding the \r\n after the <some#body.com>. I've found that php can be very picky when talking to mail servers.
Edit: just to help a little more, I have this (almost exactly what you have) in one of my working scripts:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: '.$to . "\r\n";
$headers .= 'From: ' .$from. "\r\n";
...where $from = $fromname.' <'.$fromemail.'>'; and $to is just an email address.
Related
I¨ve got a problem answering mails sent from my website, as the senders emailaddress isn´t showing anywhere, only the webmasters email
Here is my code:
<?php>
$from="kim.s.nielsen#mail.dk";
$email="info#intotext.dk";
$name=$_POST['name'];
$message=$_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $fromName . ' <' . $fromEmail .'>' . " \r\n" . 'Reply-To: '. $fromEmail . "\r\n" . mail($email, $name, $message, $headers);
print"Din besked er sendt. Vi vender tilbage så hurtigt som muligt." ?>
Use this format to send your email, this will show the senders email address, try this. you have concatenated the mail function with your header, mail() is not header it is used to send your email.
$fullname = "full name";
$from = "sender#mail";
$to = "reciever#mail";
$subject = "Your subject";
$message = "<h1> heading </h1><p> Message </p>";
$headers = [
'MIME-Version: 1.0',
'Content-type: text/html; charset=iso-8859-1',
'From: ' . htmlspecialchars($fullname) . " <$from>",
'X-Mailer: PHP/' . phpversion()
];
mail($to,
htmlspecialchars($subject),
nl2br(htmlspecialchars($message)),
implode("\r\n", $headers)
);
This question already has answers here:
PHP Mail, CC Field
(3 answers)
Closed 7 years ago.
this is my code, But i am getting blank mails also. what was the wrong with this?
'success',
'message'=>'Thank you for contact us. As early as possible we will contact you '
);
$name = #trim(stripslashes($_POST['name']));
$email = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$email_from = $email;
$email_to = 'To: <someone#gmail.com>, <anotherone#gmail.com>' . "\r\n";
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
Please read documentation mail function Here they explained detailedly.
Particularly Example #4 Sending HTML email
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// 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);
By mistake, I added from-address as to-address in mail-function.
It sends mail to both to-address and from-address why? Is it documented anywhere?
$from = 'from_user#gmail.in';
$to = 'to_user#gmail.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$message = json_encode(compact('to', 'from', 'headers'));
// NOTE THE FROM INSTEAD OF TO
mail($from, $subject, $message, $headers);
Further to the comments and to highlight your request for reference. Here is a snippit from the php manual for reference. Notice the first line of additional headers:
// 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: 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);
So you are sending an email both through the mail($to... (which happens to be the $from in your case) but you are also sending the $to in the $headers declaration.
I can't get the syntax quite right with PHP. How do I change it to display the sender's full name as well as their email address in the 'From:' part this PHP email script?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "From: " . $_REQUEST['email'] . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message .= 'Name: ' . $_REQUEST['name'] . "<br>";
$message .= $_REQUEST['message'];
I tried
$headers .= "From: " . $_REQUEST['email'] '<'$_REQUEST['name']'>'. "\r\n";
But I've screwed up the code somewhere.
Thanks guys!
Mail headers are Person Name <email#example.com> so your header needs to be:
$headers .= "From: $_REQUEST[email] <$_REQUEST[name]>\r\n";
I am new to PHP and send an email using following code
<?php
$to = 'to#xyz.com';
$subject = 'the subject';
$message = '<table dir="rtl"><tr><td>'. "\r\n";
$message .= '<b>This is Bold</b></br> <i> This is Italics</i></br>شطب 14 مرشحا لمجلس الأمة الكويتي'. "\r\n";
$message .= '</td></tr></table>';
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n" .
$headers .= 'From: from#xyz.com' . "\r\n";
$headers .= 'Reply-To: replyto#xyz.com' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
ini_set ( "SMTP", "smtp.xyz.com" );
mail($to, $subject, $message, $headers);
?>
I can receive the email and it display the arabic also but it also show the from email address in the body of the email.
And other issue is that arabic is RTL even after mentioning in table dir-"RTL" it still show the message as LTR.
Example of Email Received
from#xyz.com
This is Bold
This is Italics
شطب 14 مرشحا لمجلس الأمة الكويتي
You could try using the alternative of CSS2 style:
style="direction:RTL; unicode-bidi:embed;"
Extra reading: http://www.i18nguy.com/markup/right-to-left.html