Cant send php mail but no error is shown [duplicate] - php

This question already has answers here:
Setting up a Ubuntu/Apache/PHP machine to send email
(5 answers)
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
Hi,
I am running a Centos 7 but I cant send php mail. I dont get any error whatsoever. The mail simply wont reach its destination.
This is my script:
<?php
date_default_timezone_set('America/Los_Angeles');
mb_internal_encoding('UTF-8');
if(isset($_POST['submit'])){
$name=$_POST['name'];
$email=$_POST['email'];
$subject=$_POST['subject'];
$to = $_POST['target'];
$message = $_POST['message'];
$from_name = mb_encode_mimeheader($name,'UTF-8');
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= "To: $name <$to>\r\n";
$headers .= "From: $from_name <$email>\r\n";
mail($to, $subject, $message, $headers);
}
?>
how can I configure this so it will at least let me know why is not sending the mail?
Thank you.

Related

PHP mail function is not working after "from" header is added [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm sending email using php header.
$to = 'test#email.com';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = '<h1>Test</h1>';
mail($to, $subject, $message, $headers);
This function is working properly.
But after I added "From" mail() function is not working.
$headers .= "From: from#address.com";
Any idea?
May you are trying to spoof email, so it's getting failed.
It would be great practise to keep using Reply-To with From while using mail()
$headers .= "From: from#address.com\r\n";
$headers .= "Reply-To: from#address.com\r\n";
But, personally suggest you to use SMTP instead of mail() or PHPMailer.

Preventing email from going into spam PHP? [duplicate]

This question already has answers here:
How do you make sure email you send programmatically is not automatically marked as spam?
(24 answers)
Online SpamAssassin evaluation / RFC conformant check [closed]
(1 answer)
Closed 4 years ago.
I'm using the mail() to send a simple email but from some reason everything I try it goes straight to spam, am I missing something here?
<?php
$to = "toemail#example.com";
$subject = "your subject";
$body = "<p>Your Body</p>";
$headers = "From: Sender Name <from#example.com>" . "\r\n";
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $body, $headers);
?>
You need an additional 'Reply-to' Header to ensure that the sender e-mail address is the same as the reply-to mail address. This should solve your problem.
e.g $headers = "From: $from\r\nReply-to: $email";
Also make sure that your headers are seperated by \r\n

Mail sending error PHP, didn't get message [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
This is my code. I spent hours debugging it. I can't see the error. Why didn't I didn't receive the email?
if(isset($_POST['submit'])){
$to = "admin#example.com";
$subject = "Mesej Website";
$from = $_POST['email'];
$headers = "From: " . strip_tags($from) . "\r\n";
$headers .= "Reply-To: ". strip_tags($from) . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<h3>Mesej Daripada '.$_POST['name'].'</h3>';
$message .= '<div style="margin-top:20px;">'.$_POST['message'].'</div>';
$message = '</body></html>';
mail($to,$subject,$message,$headers) or die('mail sending error');
The in built mail function of PHP needs configuration for sending the email.However, if you are using the third party hosting provider this should be already configured or else you need to configure it in php.ini file.
To avoid these configuration issues you can use the phpmailer library where you can all the parameters easily and in a more efficient way.

sendemail.php- how can i make the php script to sent email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 5 years ago.
I am using contact us form in my website and i want to send email through this. i got a sendemail.php script and integrated with my website. But when i filled the form and sent it, it shows email is sending and its forever. How can i make it to send email. Also do we need to host it in the website? I have it in my system and have to test the mail function before host the website. Here is my php script.
<?php
$name = #trim(stripslashes($_POST['name']));
$from = #trim(stripslashes($_POST['email']));
$subject = #trim(stripslashes($_POST['subject']));
$message = #trim(stripslashes($_POST['message']));
$to = '<myemail#domain.com>';//replace with your email
$echo =("Thank you for contacting us!");
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, $headers);
die;
The PHP mail() function will essentially try to send your email using whatever mail server you have pointed it to in your php.ini.
So, for mail() to work on your local machine you need to set up a local mail server.

php mail spam problems [duplicate]

This question already has answers here:
sending email via php mail function goes to spam [duplicate]
(6 answers)
Closed 7 years ago.
$to = $_POST['email'];
$subject = 'Your password';
$message = $_POST['password'];
$headers = 'From: https://client.yourtradechoice.com/ no_reply#yourtradechoice.com' . "\r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .='X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
mail($to, $subject, $message, $headers);
mail sending in spam how to fix it ?
Don't use php mail function to send email. Use php mailer script like Swiftmailer & use SMTP server to send emails.

Categories