Why is this mail going straight to SPAM box? - php

I am using the following script to send mail
<?
extract($_POST);
$subject = "Feedback from ".$name." (".$email.", Ph: ".$phone.")";
$mail = #mail($send,$subject,$content);
if($mail) { echo "Your feedback has been sent"; }
else { echo "We are sorry for the inconvienience, but we could not send your feedback now."; }
?>
But this is always ending up in the spam Folder. Why?

You have to use headers while you send mail, to prove that the mail arrives from a genuine source and not a bot.
Try this!
<?
extract($_POST);
$subject = "Feedback from ".$name." (".$email.", Ph: ".$phone.")";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From:'.$email."\r\n";
$headers .= 'Reply-To: '.$email;
$mail = #mail($feedback,$subject,$content,$headers);
if($mail) { echo "Your feedback is send"; }
else { echo "We are sorry for the inconvienience, but we could not send your feedback now."; }
?>

Related

not able to send mail from php

I want to send a email from php mail function. This is my code
<?php
$to = "modiv2301#gmail.com";
$subject = "HTML email";
$message = "
<h1>this is msg</h1>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <modiv2301#gmail.com>' . "\r\n";
$success=mail($to,$subject,$message,$headers);
if (!$success) {
$errorMessage = error_get_last()['message'];
print_r($errorMessage);
}else{
echo "Success";
$errorMessage = error_get_last()['message'];
print_r($errorMessage);
}
?>
when i run this code its showing me Success but i am not Receiving any email

PHP - Not receiving email from contact form

I am not receiving emails from this contact form, but the message seems to sending okay and it also redirects me to the sent page.
I don't have access to the server only via FTP.
PHP
<?php
$to = 'test#gmail.com';
$subject = $_POST['subject'];
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$body = <<<EMAIL
<html>
<p><h3>Email Submited From Website.</h3></p>
<p><strong>Name:</strong> $name</p>
<p><strong>Email:</strong> $email</p>
<p><strong>Subject:</strong> $subject</p>
<p><strong>Message:</strong> $comment</p>
</html>
EMAIL;
// 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: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
//$headers .= 'Cc: noreply#example.com' . "\r\n";
//$headers .= 'Bcc: noreply#example.com' . "\r\n";
if ($_POST['submit']){
mail($to, $subject, $body, $headers);
header ("Location: message-sent.php");
die();
} else {
header ("Location: message-failed.php");
die();
}
?>
Check if mail is actually being sent:
if (mail($to, $subject, $body, $headers)===false) {
echo "Not sent!";
} else {
echo "Sent!";
}
Change this:
$headers .= 'To: test email' . "\r\n";
$headers .= 'From: <website#mt.co.uk>' . "\r\n";
To this:
$headers .= "To: $to <test email>\r\n";
$headers .= "From: website#mt.co.uk <website#mt.co.uk>\r\n";
Also, you need to sanitize the subject and body of the email so that the email arrives, but this will usually be reflected in the results after email() reports a success, in that case the email will bounce, go to the spambox, or simply be refused.
If your hosting provider doesn't have an email server, you could try to use a free email server and phpMailer. https://github.com/PHPMailer/PHPMailer

Why is my PHP script not sending emails when set from header

I have a php script that is only sending mail when the user registration.
I put in something along the lines of:
$to ='testmail#gmail.com';
$message = 'Hello';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Website <admin#example.com>\r\n";
if($results= mail($to, 'User Registration', 'Test', $headers)) {
echo 'success';
} else {
echo 'fail';
}
But the email doesn't send on server. When i put the following line :
$headers .= "From: Website <admin#example.com>\r\n";
Why is this happening?
Have you looked at the answer to smtp configuration for php mail it's very similar a question to yours?

PHP - Email is not sending

There are two steps first the email i sent to the person who wants the newsletter and the second email needs to be sent to info#dirtytrend.com. The problem is that the email is sent in the first step but the email in the second step is never getting through but the code seems to carry on without any errors.
The code is below
<?php
$name = $_POST["nameofperson"];
$to = $_POST["emailofperson"];
$subject = "Hi!";
$body = "Hi " . $name . ",<br><br>Thank you for subscribing?\n\nWe have logged your email to process your newsletter and you will recieve an email from us confirming your subscription.";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
if (mail($to, $subject, $body, $headers)) {
$body2 = "Name: " . $name . "\n";
$body2 .= "Email: " . $to;
if(mail("info#dirtytrend.com", "Subscription Request", $body2)){
header("Location: http://www.dirtytrend.com/events.html");
}
else{
}
} else {
echo "ERROR: Email not sent please contact the system administrator";
}
?>
In the second mail() you have only 3 parameters and you're missing the 4th one with the headers so maybe it is recognized as spam?

Putting images in a PHP email

I have set up a mail form to send emails from my webpage, and I would like to be able to set up images in these emails. This is the code I currently have:
$to = "test#test.com";
$subject = "Emergency details";
$body = "Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/".$passport."'/>";
if (mail($to, $subject, $body)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
When I send this email, the outputs looks like this:
Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/test.jpg"/>
and actually displays the code rather than the picture. Is it possible to make this display the picture instead?
Thanks for any help
That's because you're actually sending a text mail and not an HTML mail. You have to set the proper headers.
Have a look at the mail() function manual : http://php.net/manual/en/function.mail.php
Specifically : Example #4 Sending HTML email
// 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";
you are sending this email as plain text. You should specify that it should be interpreted as an html mail by using mail()'s fourth argument (headers).
Example can be found in the documentation.
The snippet:
// 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";
You are sending a simple mail and due to this it is interpreted as text only. What you want to do is to send a mail containing html instead of simple text. This require that you include headers to the mail explaining the content of the mail.
Try this:
$headers .= "--$boundary\r\n
Content-Type: text/html; charset=ISO_8859-1\r\n
Content-Transfer_Encoding: 7bit\r\n\r\n";
$to = "test#test.com";
$subject = "Emergency details";
$body = "Passport picture: <img src='http://www.test.co.uk/files/passport_uploads/".$passport."'/>";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
(example snapped from http://www.daniweb.com/web-development/php/threads/2959)

Categories