PHP - Not receiving email from contact form - php

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

Related

Mail getting with HTML tags

My mail function is working fine, delivering mail after filling the form.
But the output in the mail is with HTML tags as shown attached.
Here is my code.
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
mail($admin_email, "$subject", $comment, "From:" . $email);
echo "Thank you for contacting us!";
}
?>
How can i get Output like this.
Location : Hyderabad
No of Bags : 50
Use the below Headers to send email with HTML tags:
// 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";
Updated Code:
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
echo "Thank you for contacting us!";
}
?>
Hope this will be help.
you have to set header's
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to, $subject, $message, $headers);
Add following headers :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Pass $headers as 4th parameter in mail function.
You need to set the Content-type header in your email message:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and pass into
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
Your message body also needs to be contained in <html> tags.

postfix send email subject breaks the FROM

I am using postfix to send an email to the user, but the problem is it breaks the words where it finds the space.
Here is the screenshot:
postfix-send-email
PHP code to send an email:
<?php
$subject = "Status Of mail";
$message = "Test Email using Postfix Apache2";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
$send = mail('test#yahoo.com', $subject, $message, $headers);
if($send)
{
return 1;
}
else
{
return 0;
}
?>
Try replacing
$headers .= 'From: 'The Travel Worthy' 'pathik#gmail.com"\r\n";
with
$headers .= "From: The Travel Worthy <pathik#gmail.com>\r\n";

Add bold text in mail sender text

Here is the code:
$email_body = "You have received a new message. ".
" Here are the details:\n\n Name: $name \n Email: $email_address \n Message \n $message";
I want to add bold text to: "Name:", "Email:", and "Message"
I have tried using the "< b > name: < /b>" (without space of course), but it doesn´t work. I want the text to be bold when i receive the mail.
// 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";
$email_body = "You have received a new message. ".
" Here are the details:\n\n <strong>Name:</strong> $name \n <strong>Email:</strong> $email_address \n Message \n $message";
// Mail it
mail($to, $subject, $message, $headers);
You need To Set Header Content Type Like This:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Here is Example ....
<?php
$to = 'recivermail#email.com';
$subject = 'Your Subject';
$from = 'sender#email.com';
// 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";
// Create email headers
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
// Compose a simple HTML email message
$message = '<html><body>';
$message .= '<h1 style="color:#f40;">Your Title</h1>';
$message .= '<b style="color:#080;font-size:18px;">How Are You?</b>';
$message .= '</body></html>';
// Sending email
if(mail($to, $subject, $message, $headers)){
echo 'Your mail has been sent successfully.';
} else{
echo 'Unable to send email. Please try again.';
}
?>

Changing header "From: noreply#domain.com" to other value, sends mail into spam folder

I have this php mail() code on my site, which works fine.
It is an ecard system, my client can fill out the from info (name, email) and to info (name, email), etc and Mail goes straight to Inbox, on google, hotmail, yahoo, etc.
When the receiver gets the email he can use the reply button, and it gets the right info.
The problem is the From: header in my mail form, I want to change this from noreply#example.com to the receiver's info, or any other info. When I do that, the mail goes into SPAM mail.
Here is the code I'm using
<?php
$name = $_REQUEST['name'] ;
$motive = $_REQUEST['email'] ;
$name2 = $_REQUEST['name2'] ;
$email2 = $_REQUEST['email2'] ;
$message = $_REQUEST['message'] ;
$subject = $_REQUEST['subject'] ;
$message = urldecode(stripslashes($message));
$headers = 'From:' . $name . ' John Q<noreply#example.com>' . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers.= "Reply-To:" .$name. "<" . $motive. ">\n";
$headers.= "Return-Path: My Company<admin#datatopixels.com>\n";
$headers.= "X-Mailer: PHP". phpversion() ."\n";
$messagee = "
<html>
<head>
<title>Title here</title>
</head>
<body>
<center>
<br>
</center>
</body>
</html>
";
mail($to, $subject, $messagee, $headers);
?>
You must to add a needle headers:
Sample code :
$headers = "From: myplace#example.com\r\n";
$headers .= "Reply-To: myplace2#example.com\r\n";
$headers .= "Return-Path: myplace#example.com\r\n";
$headers .= "CC: sombodyelse#example.com\r\n";
$headers .= "BCC: hidden#example.com\r\n";
if ( mail($to,$subject,$message,$headers) ) {
echo "The email has been sent!";
} else {
echo "The email has failed!";
}
?>
And I would suggest to read oswalds's

how to i send bcc or cc email in my mail function but i have tried code but bcc or cc function is not working? [duplicate]

i want to use bcc or cc function in this mail function?
Here My Mail Function
<?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply#mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via this message to log in. Click the following link to do so: http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'#'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message, $headers);
?>
You should add to the to and headers part of the mail.
For TO part
$to = "to#to.com, cc#cc.com"
For HEADERS part
$headers .= "To: To Name <to#to.com>\n";
$headers .= "CC: CC Name <cc#cc.com>\n";
$headers .= "BCC: BCC Name <bcc#bcc.com>\n";
It is very simple, just sharing if anyone gets help from here:
//......
//...Other setting goes here....
// 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: My Name <myemail#example.com>'. "\r\n";
//Multiple CC can be added, if we need (comma separated);
$headers .= 'Cc: myboss1#example.com, myboss2#example.com' . "\r\n";
//Multiple BCC, same as CC above;
$headers .= 'Bcc: myboss3#example.com, myboss4#example.com' . "\r\n";
mail($to, $subject, $message, $headers);
Just add the Bcc/CC in your Code
<?php
//SENDS EMAIL THAT TELLS THE USER TO ACTIVATE THE ACCOUNT
$activation = 'activation.php?key='.$key;
$your_email = 'non-reply#mydomain.pk'; //CHANGE TO YOUR SETTINGS
$domain = $_SERVER["HTTP_HOST"]; //YOUR DOMAIN AND EXTENSION
$to = $email;
$subject = 'MyDomain Activate Account';
$message .='<img src="http://mydomain.com/images/securedownload.jpg"/>';
$message = 'Welcome,<br/> '.$_POST['username'].'. You must activate your account via this message to log in. Click the following link to do so: http://'.$domain.'/'.$activation;
$headers = 'From: Mydomain<'.$your_email.'#'.$domain.'>\r\n'; //MODIFY TO YOUR SETTINGS
$headers .= "BCC: email#domain.com;\r\n"
$headers .= 'Content-type: text/html\r\n';
mail($to, $subject, $message, $headers);
?>

Categories