I am attempting to send a confirmation email from a PHP script. I tested on gmail and it worked fine (the email was sent with appropriate subject and contents), however when I tried sending an email to a yahoo account, the subject field was correct but the contents were sent as an attachment as opposed to text inside the actual email. Here is the mailing code.
$headers = 'From: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= 'Reply-To: ' . 'orders#COMPANY_NAME.com' . "\r\n";
$headers .= "BCC: orders#COMPANY_NAME.com \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text; charset=ISO-8859-1\r\n"
mail($email, "COMPANY_NAME Order Confirmation $confirmation_number", $text, $headers);
How can I send an email to yahoo that will include $text inside the email as opposed to an attachment?
It may be because of a wrong "Content-Type" header: I do not think "text" is a valid content type.You should try, instead, with "text/plain".
Content-Type: text/plain; charset=ISO-8859-1
PS: you may also want to consider using UTF-8 instead of ISO-8859-1.
Related
i am having a issue with sending emails with cronjobs.
actually i need to send email to all the recently joined users
and so the emails are something like $to='acx1#xyz.com,acx2#xyz.com,acx3#xyz.com';
here i need to send the mail to all the receipts but not to let them know that i have sent this mail to all these persons in receipt basically BCC them
but the problem is that if i put the $to into BCC then what should i put in to function of mail
if to is empty then it may be spamed
i want to send this mail to all the receipts but when they check the headers they should see their email only
and one more issue please let me know if i am using correct headers ?
because sometimes my email is spammed by gmail
$from='tests.com';
$to='contact#test.com';
$message="<body> some html data with inline css </body>"
$subject="Hii this is test";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= "From: $from <contact#test.com>" . "\r\n";
$headers .= "Reply-To: contact#test.com" . "\r\n";
$headers .= 'BCC: acx1#xyz.com,acx2#xyz.com,acx3#xyz.com' . "\r\n";
mail($to, $subject, $message, $headers);
When sending an email I want to show the hyperlink value not the whole href.
This is my code
if ($model->update(array('status')))
{
$body.="Your account has now been verified. Please, login and spiff up your profile and take a look at our ,";
$body.="<a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>";
$body.="to start building your business!";
$email=$model->email;
mail($email,$subject,$body,$headers);
//----------------------------------------------------------//
$this->redirect($model->user_id);
}
I want to send sponsored program not the whole href in the mail body. But whenever I send an email using this it prints <a href='https://contactcenters.com/page/58/?Advertisewithus'>sponsorship program</a>"; instead of Sposorship Program
I have tried to add double quotes inside single quotes but it didn't work.
You need to add to headers:
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
if you haven't done it yet.
Also you have to make sure your e-mail client is properly set. For example in Mozilla Thunderbird you may set it to display only TXT and then it may perform some changes to the content. Otherwise you may send email correctly but you will result you don't expect
Based on http://php.net/manual/en/function.mail.php
You need to inform mail engine, that you are sending something more complicated then just text
// 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";
// Mail it
mail($to, $subject, $message, $headers);
You are sending the mail as plain text, so html would not be recognized. Add these to the $headers:
$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
See http://www.php.net/manual/en/function.mail.php
When I added "a href tag " in the mail body the mail is not sent.
If I remove this 'a href and www' tag, the mail sends and all other content display as per my requirement.
I don't know where is the exact problem, I'm using GoDaddy hosting with PHP 5.3 version.
If anyone has a better solutions please share with me .
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<a href=www.google.com>Click here</a>';
// To send HTML `enter code here`mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
// Additional headers
$headers .= 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
Use this as the header:
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
that's if you want to use HTML in the body, but you have to create well formatted HTML, you know with all of its tags: html, head, body, and close them all.
<html>
<head></head>
<body>Content here and this is a link</body>
</html>
I had the same problem once, turned out my spam filter blocked the mail when a link was in it and let it trough when I removed the link.
Took me some time to notice that
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 have this code at the top of my email php file which sends out emails
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: $from <$from>" . "\r\n";
$headers .= 'Cc: matt.e#posnation.com' . "\r\n";
$headers .= 'Bcc: posnation#gmail.com' . "\r\n";
I need to change this to just a plain text email ...what do i change. I was thinking the second line text/html to text/text but i wasnt sure
You want to change the "text/html" to "text/plain".
You can use text/plain
But if you enter html content the tags and all will be shown on the client though ...
But i'm sure there's an alternate way to support both text and html ...
Are you using the built in mail function or an external mail app like phpMailer?
You don't need to change anything.
Technically it should be "text/plain", but if you want, you can just as easily send an "HTML" email with no HTML tags and it will work just fine.