I am using html email templates to send mail with image. and when i forward it to another mail then html template format is broken. I am using html templates in the following manner -
$message = file_get_contents('templates_folder/templatename.html');
mail($to, $from, $subject, $message);
and the image is defined in html template format is as follows -
<img src="urlofimage" />
Thanks in advance!
You should build your headers for mail to make it view like a good template, else you might see only your code
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . "\r\n";
$headers .= 'From: Admin<youremail#email.com>' . "\r\n";
mail($to, $subject, $message, $headers);
Note :
Also make sure that the image you include should be available to public and it should not be your localhost image.
You can also look this example
Related
On sending a mail I've set my header to:
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
for mail($to, $subject, $message, $headers);
The Tómas is working in the content correctly but not in the from section of the email. It shows up like Tómas. Any idea how to modify the header to make this work?
Many thanks.
Tó = Tó
change the following line
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
with
$headers = 'From: Tomas<tomas#email.com>' . "\r\n";
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 know this is simple but my brain is fried from trying to solve a different problem!
I'm using php's mail function to email the user. Below is my code. See the a href link, how do I get this to display as an actual link within the php?
$email=someone#example.com;
$content= "Dear Whoever,
NB: Please click here to read and download the terms and conditions.";
mail( "$email", "Welcome", $content, "From: support#example.com");
As noted above, your code has error. It should be:
email='someone#example.com';
$content= "Dear Whoever,
NB: Please click here to read and download the terms and conditions.";
mail( $email, "Welcome", $content, "From: support#example.com");
You would need to set the mime type to HTML in the header, and use it as a parameter in the mail() function.
From the manual
// 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);
Though I usually use SwiftMailer and it has other neat features.
hay
i used this code
$to = "mial#live.com,mail#yahoo.com";
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
$headers .= 'Bcc: {$to}' . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo 'ok';
}
but see what is happend
every user see the full list of the users
alt text http://img694.imageshack.us/img694/1289/21811933.gif
Your call to mail is passing the $to as the to parameter meaning those emails will be be in the to header try passing an empty string instead. You are passing the info into the bcc header so the email should still get to them that way.
That is because you have put all the users in the "to" line. You are also passing them into the "bcc" line too so just doing this may help you but as far as I know you need at least one address in the to line (although this may not be the case). It'll look pretty strange for each person doing it that way though.
The best way to avoid these issues would be to send the email multiple times, once to each user. To modify your code example to do this, I'd do something like the following:
$toAddresses = array("mial#live.com", "mail#yahoo.com");
$subject = "Mini-mass Emailer";
$message = "<a href='#'>Hello World</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Your Name <me#mydomain.com>' . "\r\n";
foreach ($toAddresses as $to) {
if(mail($to, $subject, $message, $headers)){
echo "OK - sent message to {$to}";
}
}
The easiest way is to take this Mail-Class of phpguru.org:
http://www.phpguru.org/static/htmlMimeMail5
There you can specify with setBcc() the addresses which should be "blind", it's pretty easy and works well. I use this class in every project.
Best Regards.