i am trying to send html image mailer using php mail function on linux platform. There is one issue when i am trying to send simple html content then it successfully get delivered to its subscriber. but when i try to send emailer which contains few images then it fails to deliver it. below are two codes 1 by which simple html is delivered. 2 which is not getting delivered.
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
code 2:
<?php
//change this to your email.
$to = "abhinav#xyz.in";
$from = "abhinav.1#gmail.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message= <<<EOF
<html>
<body bgcolor="#DCEEFC">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color="red">Thanks Mohammed!</font> <br>
* maaking.com
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>
EOF;
//end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa#p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email#maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
I corrected the code by which I am able to send image mailer below is the code:
<?php
$to= 'abhinav#xyz.com' . ',';
$to .= 'abhinav#gmail.com';
$sub='test1';
$msg= <<<EOF
<html>
<body>
<table>
<tr>
<td><img src="http://d32vlg867bsa1v.cloudfront.net/z/prod/w/2/i/zovi-logo2.png" />
</td>
</tr>
</table>
</body>
</html>
EOF;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: <centos_test#example.com>' . "\r\n";
mail($to,$sub,$msg,$headers);
?>
I am still working to sent highly customized mailer and will describe how it can once I found how it can be done.
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I would like to send an email using php and I have used this code:
<?php
// multiple recipients
$to = 'x#example.com' . ', '; // note the comma
$to .= 'y#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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);
?>
What I do is to save this file as a example.php file and upload it to a directory in my ftp. Then I use a browser to go to site.com/directory/example.php
and I think the code runs but it can not send the emails.
Should I configure anything else in the cpanel or the server to use this code?
<?php
$to = "abc#example.com";
$subject = "This is subject of mail";
$message = "
<html>
<head>
<title>".$subject."</title>
</head>
<body>
<p>This here is the description of mail</p>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: thesender#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
echo "<script> alert('Form Succesfully Submitted'); window.location.href='contact.php'; window.location.href='contact.php'; </script>";
?>
Try this out.
If you need the Cc:, or Bcc include them after in headers variable.
I am building a website contact form that uses MAILTO to send text that the user submits via the web form. However, the email account that receives the MAILTO text comes in 'ugly' and was wondering if there was a way to get that text into an HTML format to enhance visually without having to rely on some back-end script.
Or, is there a better way to do this?
Thanks.
you can't format html body using mailto, you need to use mail() function of php,
here is short example:
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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);
?>
more detail: http://php.net/manual/en/function.mail.php
i need to send a mail from CRM to a particular gmail account using php , the from and to mail id's are default.the user need to enter the subject and the body of the mail only in graphical view like as outlook express.
I think this manual will help You
Mail php manual
sample script
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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);
?>
Here i have a problem when iam sending a mail.It is delevering properly but when iam trying designing the message body with HTML tags it sending the same html tags to my email inbox.How can i overcome this please tell me.
Here the PHP code:
$to = "$email";
$subject = "Test mail";
$message = '<!Doctype html><html><head><title>Confirm Link</title></head><body><div style="color:blue">Thank u for registering with us </div>
<div> Hi'.$name.' Please click the below link to activate your accont</div><div>Active your account now</div> </body></html>';
$from = "abc#gmail.com";
$headers = "From:" . $from;
Here my deliverd email inbox message:
here designing not working it display same as my program code.Please help me.
Confirm LinkThank u for registering with us
HiSrinivas Please click the below link to activate your accontActive your account now
// 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";
Note:
If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package ยป PEAR::Mail_Mime.
Reference
Send an HTML email:
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>
The problem may be that you are not setting the mail headers. Try this:
// 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($to, $subject, $message, $headers);
I am trying to create an autoresponder email and the content is a PHP variable. I want it to output HTML code and right now it's not.
//Example:
$respondmessage = " Hello $fullname,
We are confirming your Appointment today!
Please click here to confirm!
";
This outputs:
Hello Your Name,
We are confirming your Appointment today!
Please click here to confirm!
In the email. Is there a way to make the email accept HTML code?
You can following line as an header in your code :
$headers = "Content-type: text/html\r\n";
This will help you to create email into HTML
Assuming you're using the built in mail function in PHP:
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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);
?>
This example is from: http://us2.php.net/manual/en/function.mail.php
The important part is the $headers variable.
By the way, as andrewsi mentioned - you need to escape your quotes:
$respondmessage = "Hello $fullname,
We are confirming your Appointment today!
Please click here to confirm!";
You have to include this header to your email script
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
From http://php.net/manual/en/function.mail.php example# 4
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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);
?>