PHP Mail() Doesn't Work

Send mail using PHP doesn't work for me

Various hosts have different limitations or requirements when an email is sent from a PHP-script, thus all PHPMailer library features can't always be used. In this answer I have information about One.com since the question stated One.com was used and I also use that host.

One.com possible mail settings

Host, username and password need to be provided as stated in the question.

The allowed authentication and encryption settings depend on which port that is used, these are all alternatives at One.com but the technical support have verified that all the settings can not currently be used in a PHP-script:

  • Port 25: authentication false or STARTTLS
  • Port 2525: authentication false or STARTTLS
  • Port 465: TLS eller SSL
  • Port 587: authentication false or STARTTLS

Within a PHP-script only the following can be used:

  • Port 25: authentication false

Example code verified at One.com

Below you can see code that is working at One.com servers if you replace the username and password with your own.

/*** Prepare email information ***/
require_once "Mail.php";
$from = "USERNAME@YOUR.DOMAIN";
$to = "SOMEONES.MAIL@gmail.com";
$subject = "Testing PHP SMTP mail";
$body = "Hi,\n\nit seems to be working don't you think?";
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, 'Reply-To' => $from);

/*** Send email ***/
$SendMail = new Mail();
$smtp = $SendMail->factory('smtp',array(
'host' => "mailout.one.com",
'port' => 25,
'auth' => false,
'username' => "YOUR_MAIL_USERNAME",
'password' => "YOUR_MAIL_PASSWORD"));
$mail = $smtp->send($to,$headers,$body);

/*** Check for errors ***/
$ErrorCheck = new PEAR;
if ($ErrorCheck->isError($mail)){
echo("<p>".$mail->getMessage()."</p>");
}else{
echo("<p>Message successfully sent!</p>");
}
?>

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']);
}
?>

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 Not Sending Email

There may be many reasons, for example you should study what SPF is.

The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)

You should use in the From something ending in @yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)



Related Topics



Leave a reply



Submit