Why doesn't this php mail script work? - php

I made a php script that sends mail. It worked fine until i changed it so it sent stuff as html instead of just plain text. However, it isn't working. The script itself returns a success, but I'm not getting the email. I've checked my spam folder. Could anyone see why this isn't working? Thanks
<?php
$to = $_POST["mail"];
$subject = 'Registration at Campatet';
$message = '
<html>
<head>
<title>Registration at Campatet</title>
</head>
<body>
<p>Thank you for registering at Campatet!</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>
';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: no-reply#campatet.com" . "\r\n";
if(mail($to, $subject, $message, $headers)){
echo "Success sending e-mail to: <b>".$to."</b>";
}
else{
echo "There was a error";
}
?>

Use this as your only header:
$headers = "Content-type: text/html; From: no-reply#campatet.com";

First, try removing the line
$headers = "MIME-Version: 1.0" . "\r\n";
Are you sure that the post variable is receiving it's address correctly? Try removing that and replacing it with the email address you are trying to use.
Have you ever been able to successfully send mail from your website at all?

Specifying email headers without a Reply-To header is often considered as reason to suspect spam. It doesn't matter that you don't want replies, just specify the Reply-To header.
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= 'From: no-reply#campatet.com' . "\r\n" . 'Reply-To: no-reply#campatet.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();

Related

Php mail function unable to send HTML

I am trying to send an email with a link, the problem im facing is that outlook does not reconize the HTML which is being put in the email.
$onderwerp = "test";
$bericht = <<<EOT
<html>
<head>
<title>Email_test</title>
</head>
<body>
* the link
</body>
</html>
EOT;
$headers = 'From: ' . $verstuurd_van;
mail($naar_1, $onderwerp, $bericht, $headers);
Thanks in forehand for the help.
In order to be able to send a HTML email you need to add a few more headers:
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
So the entire email becomes something like:
$to = 'example#example.com';
$subject = 'Test';
$message = "
<html>
<body>
<p>
Hallo <b>Example</b>,
</p>
</body>
</html>";
$headers = "From: example#example.nl\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
mail($to, $subject, $message, $headers);
Also take a look at: https://css-tricks.com/sending-nice-html-email-with-php/
just mention the headers in your email script like .
// 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";
so your script will
$onderwerp = "test";
$bericht = <<<EOT
<html>
<head>
<title>Email_test</title>
</head>
<body>
* the link
</body>
</html>
EOT;
$headers = 'From: ' . $verstuurd_van;
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($naar_1, $onderwerp, $bericht, $headers);
you can take reference from html email with php or w3school email html

How to send an email using php step by step? [duplicate]

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.

How to visually enhance MAILTO data submitted text?

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

Sending Mail through PHP

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);

PHP mail html format not working

Using php, and with this code I receive the email as a plain text, did I miss something? as I need to send formatted email which could contain links for example.
$to = "receiver#test.com";
$subject = "Password Recovery";
$body = '
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<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>
';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info#test.net\r\n"."X-Mailer: php";
if (mail($to, $subject, $body, $headers))
echo "Password recovery instructions been sent to your email<br>";
You've re-set your headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From: info#test.net\r\n"."X-Mailer: php";
You're missing a dot in that last line, which is over-writing the previous two:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info#test.net\r\n"."X-Mailer: php";
Look at this example, this is sufficient to send mail in php:
<?php
//change this to your email.
$to = "abc#gmail.com";
$from = "Example#example.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message ="
<html>
<body>
<p style=\"text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;\">
<b>I am receiving HTML email</b>
<br/><br/><br/><a style=\"text-decoration:none;color:#246;\" href=\"www.example.com\">example</a>
</p>
<br/><br/>Now you Can send HTML Email
</body>
</html>";
//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 found the same problem with a specific mail server, in my case the solution was to set "\n" instead of "\r\n" as the end of line for the headers.
Even though your problem seems to be caused by re-assigning to $headers, I've ran into a similar problem and discovered the cause to be the double line-ending "/r/n". Some mail apps such as Bluemail, start the mail body (effectively ending the headers) after reading a double line ending.
In my case, it was solved by changing this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: info#test.net\r\n"."X-Mailer: php";
to this:
$headers = 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
$headers = "From: info#test.net\n"."X-Mailer: php";

Categories