For some reason when I send an email message, the HTML is still being displayed in plain text. Can someone please tell me what I'm doing wrong here?
Here is the code:
$to = $_SESSION['customer_email'];
$from = "noreplay#mysite.com";
$subject = "Confirmation for Appointment on ".$_SESSION['display_date'];
$headers = "From: ".$from."\r\n";
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
$headers .= "MIME-Version: 1.0;\r\n";
$message = "<p>Thank you".$_SESSION['firstname']." for booking online. Your appointment has been confirmed and is scheduled for <strong>".$_SESSION['display_date']."</strong> between the hours of <strong>".$_SESSION['display_time']."</strong>.</p><p> Please expect our crew to arrive between your two hour arrival window. You will receive a courtesy call when our crew is <span>15-30 minutes</span> away. A confirmation email has been sent to <strong>".$_SESSION['customer_email']."</strong>. </p><p> If you have any questions or need to make any changes to your appointment, please contact our office at <strong>1-800-333-1111</strong>. Thank you for choosing Us!
</p>";
if(mail($to, $subject, $message, $header ))
{
$msg = "Your message has been sent";
}
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
should be
$headers .= "Content-type: text/html; charset=UTF-8;\r\n";
Two typos:
if(mail($to, $subject, $message, $header ))
should be
if(mail($to, $subject, $message, $headers ))
and in
$headers .= "Content-type: text/html; charseet=UTF-8;\r\n";
change your 'charseet' to
Content-Type: text/html; charset=ISO-8859-1\r\n
It appears nowadays you can use UTF-8
Content-Type: text/html; charset=UTF-8\r\n
and
if(mail($to, $subject, $message, $header))
to
if(mail($to, $subject, $message, $headers))
also mail's RETURN:
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.
It is important to note that just because the mail was accepted for delivery, it
does NOT mean the mail will actually reach the intended destination.
Related
im sending a batch email to multiple recipients using:
mail(implode(',', $emails), $subject, $content, $headers);
however, each person can see the list of who the email was sent to. I want to keep this private, and also so the email appears more personal.
is there a way to do this without sending a mail() to each email, as I'm guessing this will take a long time to run?
You are looking for a simple BCC address. Everyone in the same mail but not able to see each others email address.
Look here: http://php.net/manual/en/function.mail.php and find the BCC.
this is the piece you need:
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: Sender Name <sender#domain.com>";
$headers[] = "Bcc: JJ Chong <bcc#domain2.com>";
$headers[] = "Reply-To: Recipient Name <receiver#domain3.com>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $email, implode("\r\n", $headers));
add a bcc header to to your message
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Bcc: email' . "\r\n";
mail($to, $subject, $message, $headers);
Before this I am sorry for my bad English
The problem is that this code
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "Reply-To: $replyTo\r\n";
$headers .= "Return-Path: $from\r\n";
$message = wordwrap($message, 68);
if(mail($to, $subject, $message, $headers))
return true;
else
return false;
Send mail, for example, when $message = 'asasasasasasas'
and doesn't send when it's more long!
I'm working on my VPS and there are many other project where it works greatly, even if the $message is big.
What am I doing wrong?
PS: mail() return true
PS2: /var/log/maillog says OK:
mail() on [/var/www/.../Controller.php:213]: To: vla*****ss#gmail.com -- Headers: From: info#mydomain.ru Content-Transfer-Encoding: base64 Reply-To: info#mydomain.ru Return-Path: info#mydomain.ru
UPD New testing shows that if i delete adresses like ttt.domain.ru in message mail() sended greatly... i can't understand..
$mailto = 'example#mail.com';
$subject = 'foo';
$message = 'bar';
mail($mailto, $subject, $message);
I open with the mail with OUTLOOK 2010, it display normally. But the mail has an attachment named "mail.html" that display "bar" when I open it in foxmail.
What is difference between these mail client? So this problem isn't seem a programming problem.
Did you use any headers?
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
Don't use foxmail so no clue if it works...but if you didn't send headers it's worth a try.
I have a mail function with the standard parameters:
mail($to, $subject, $message, $headers);
Where:
$headers = "From: admin#mysite.org";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
Now, I'm trying to get the sent e-mails to show 'My Site' as the sender instead of 'admin#mysite.org' but if someone responds to the mail it still needs to go to admin#mysite.org.
I've tried putting "My Site" in the "From" field before and after the e-mail address but it just appends to the address. I've tried appending it to the $headers variable but that messes the whole e-mail up. I've also tried adding it this way:
$headers .= "\r\nMy Site";
but that doesn't seem to do anything.
I know this can't be complicated as I've seen it done a hundred times, but I can't seem to find a straight-forward answer for this - how do I 'mask' the admin e-mail with the site name but still keep it as the address any response goes to?
Change your From: header to "From: My Site <admin#mysite.org>"
$headers = "From: My Site <admin#mysite.org>";
$headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"";
From the PHP Docs.
There is the "From: something <something#something.com>"; header, and then there is also the optional fifth parameter of mail() which allows you to override the from setting that may or may not be set in php.ini.
<?php
$to = 'name#domain.com.au';
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: Name <noreply#domain.info>" . "\r\n";
$fifthp = '-f noreply#domain.info';
mail($to, $subject, $message, $header,$fifthp);
?>
I tried to send an email vie PHP but got nothing. I don't see what I am doing wrong.
// Send an email.
$subject = 'Welcome to mypage';
$message = 'your registration went fine.';
echo $email;
$a=mail($email, $subject, $message );
echo 'Mail sent, a='.$a;
I checked that $email contains my email address and $a = 1 after running the code. Still my mailbox is empty. Why?
You probably don't have Apache configured correctly. That's why the email isn't sending.
Some mail servers require mail headers:
$header = "MIME-Version 1.0\r\n";
$header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$header .= "From: ".$sendername." <".$fromemail.">\r\n";
$header .= "X-Mailer: PHP/".phpversion();
mail($email, $subject, $message, $header);