PHP mail not working for some reason
This is probably a configuration error. If you insist on using PHP mail
function, you will have to edit php.ini
.
If you are looking for an easier and more versatile option (in my opinion), you should use PHPMailer.
PHP Mail Not Sending But No Errors
Try this to find out where is the problem
$success = mail('example@example.com','New Enquiry',$msg);
if (!$success) {
print_r(error_get_last()['message']);
}
with a glance at Php Mail Documentation
Note:
When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.
Failing to do this will result in an error message similar to Warning: mail(): "sendmail_from" not set in php.ini or custom "From:" header missing. The From header sets also Return-Path under Windows.Return Values
Returns TRUE if the mail was successfully accepted for delivery, FALSE
otherwise.It is important to note that just because the mail was accepted for
delivery, it does NOT mean the mail will actually reach the intended
destination.
update
After comments just for test, remove every code in your php file an just try the simplest way to debug
<?php
// the message
$msg = "First line of text\nSecond line of text";
// use wordwrap() if lines are longer than 70 characters
$msg = wordwrap($msg,70);
// send email
if(!mail("someone@example.com","My subject",$msg)){
var_dump(error_get_last()['message']);
}
?>
PHP mail stopped working
Could it be that E-Mails are being sent fine, but are caught by a spam filter?
If this could be, allow me to cross-post myself:
A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :
- Does the sender address ("From") belong to a domain on your server? If not, make it so.
- Is your server on a blacklist (e.g. check IP on spamhaus.org)? This is a remote possibility with shared hosting.
- Are mails filtered by a spam filter? Open an account with a freemailer that has a spam folder and find out. Also, try sending mail to an address without a spam filter.
- Do you possibly need the fifth parameter "-f" of mail() to add a sender address? (See mail() command in the PHP manual)
- If you have access to log files, check those, of course, as suggested above.
- Do you check the "from:" address for possible bounce mails ("Returned to sender")? You can also set up a separate "errors-to" address.
For german speakers, I have written a quite exhaustive "what to do" on this issue some time ago. See here.
php mail() function not working
it doesn't mean port 25 is open, it just means that PHP should use port 25 for contacting the SMTP server. You don't state what OS you're on, but note that sendmail would be a unix-only thing, and will fail if you're on Windows.
Mail function is not working in PHP
mail($to, "Subject: $subject",$message );
echo "Thank you for using our mail form";
instead of this ,first check if the mail is sent
$mail=mail($to, "Subject: $subject",$message );
if($mail){
echo "Thank you for using our mail form";
}else{
echo "Mail sending failed.";
}
By this actually u can know whether your mail function in working or not
if it is not working.the problem can be with SMTP settings in your localhost
enable errors in php if not enabled using
ini_set('display_errors',1);
PHP mail function is not working on my server?
I'd give this a try, ending each line with \r\n
and also adding a To header (redundant as it might seem). Also, declaring charset=utf-8
in the header should be enough. If not though, make sure it matches (right now there's a mismatch).
<?php
$subject = "Test mail";
$to_email = "to@example.com";
$to_fullname = "John Doe";
$from_email = "from@example.com";
$from_fullname = "Jane Doe";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
// Additional headers
// This might look redundant but some services REALLY favor it being there.
$headers .= "To: $to_fullname <$to_email>\r\n";
$headers .= "From: $from_fullname <$from_email>\r\n";
$message = "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\r\n
<head>\r\n
<title>Hello Test</title>\r\n
</head>\r\n
<body>\r\n
<p></p>\r\n
<p style=\"color: #00CC66; font-weight:600; font-style: italic; font-size:14px; float:left; margin-left:7px;\">You have received an inquiry from your website. Please review the contact information below.</p>\r\n
</body>\r\n
</html>";
if (!mail($to_email, $subject, $message, $headers)) {
print_r(error_get_last());
}
else { ?>
<h3 style="color:#d96922; font-weight:bold; height:0px; margin-top:1px;">Thank You For Contacting us!!</h3>
<?php
}
?>
I'd also replace the first line with something like this, to avoid notices / errors:
if ($_POST && isset($_POST['submit']) && isset($_POST['name']) && isset($_POST['email']) && !empty($_POST['name']) && !empty($_POST['email'])) {
Related Topics
How to Remove All Non Printable Characters in a String
Get Specific Columns Using "With()" Function in Laravel Eloquent
Search With Comma-Separated Value MySQL
PHP Regex to Get Youtube Video Id
"Connect Failed: Access Denied For User 'Root'@'Localhost' (Using Password: Yes)" from PHP Function
How to Solve "Fatal Error: Class 'MySQLi' Not Found"
Why Is the Hash Part of the Url Not Available on the Server Side
How to Get Count of Rows in MySQL Table Using PHP
PHP - How to Create a Newline Character
Are PHP Variables Passed by Value or by Reference
How to Extend a Class Using More Than 1 Class in PHP
How to Catch Curl Errors in PHP
Preserve Line Breaks from Textarea
How to Write SQL For a Table That Shares the Same Name as a Protected Keyword in MySQL
Error With PHP Mail(): Multiple or Malformed Newlines Found in Additional_Header