I am working on a project in which I need to send email. My send mail function is:
ini_set('sendmail_path', "\"C:\xampp\sendmail\sendmail.exe\" -t");
ini_set('smtp_server', 'smtp.gmail.com');
ini_set('smtp_port', 25);
ini_set('smtp_ssl', 'auto');
ini_set('error_logfile', 'error.log');
ini_set('auth_username', 'myemailAddreds#gmail.com');
ini_set('auth_password', 'mygmail_password');
//sendmail_from('myemailAddreds#gmail.com');
$to = 'myemailAddreds#gmail.com';
$subject = 'Hello from XAMPP!';
$message = 'This is a test';
$headers = "From: your#email-address.com\r\n";
if (mail($to, $subject, $message, $headers)) {
echo "SUCCESS";
} else {
echo "ERROR";
}
But I am getting following error
Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\umtab\xampp\htdocs\umtab\email.php on line 23
As you can see from the error: you get Failed to connect to mailserver at "localhost" port 25. It's written localhost, like the server is not properly set.
I think that ini_set('smtp_server', 'smtp.gmail.com'); is not working.
Try to use ini_set('SMTP','smtp.gmail.com'); instead ... that should be the correct way to set the SMTP server!
But anyway, as suggested by #ADyson, it would be better using PHPMailer. You can read the documentation and the usage right here.
Andrea
Related
Hi I am trying to test my PHP mail function but it is not working. I have shared hosting all of my website mail function are not working
<?PHP
$sender = 'xx#gmail.com';
$recipient = 'xx#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
I have also checked my php.ini if mail function is disabled but it is not disabled
disable_functions =
I also tried using Easy WP SMTP Plugin. But it is not working. I am sure that my settings are correct.
But this is what i got
SMTP ERROR: Failed to connect to server: Connection timed out (110)SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Thank you
We're struggling with email submission via PHP. Currently we're using the following code:
<?php
ini_set('display_errors',1);
ini_set("SMTP","smtp.gmail.com");
ini_set("smtp_port","587");
ini_set("auth_username","mymail_address#gmail.com");
ini_set("auth_password","mypassword");
$to = 'mydestination_address#gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: mymail_address#gmail.com';
if(mail($to, $subject, $message, $headers))
{
echo "Success!";
}else
{
echo "Failed.";
}
?>
The outcome of the code gives the following message:
Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS
command first. e22sm16110599edu.35 - gsmtp in
C:\inetpub\production\mailtest.php on line 13 failed.
Please note that our application has been created with PHP using IIS.
I think you can do it with:
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465");
Please check if your PHP installation has SSL support before use the code above.
i will send mail using php mail function but it can display some error..
Warning: mail(): Failed to connect to mail server at
"localhost" port 25, verify your "SMTP" and
"smtp_port" setting in php.ini or use ini_set() in
mail.php
<?PHP
$sender = 'sender123#gmail.com';
$recipient = 'resever123#gmail.com';
$subject = "php mail test";
$message = "php test message";
$headers = 'From:' . $sender;
if (mail($recipient, $subject, $message, $headers))
{
echo "Message accepted";
}
else
{
echo "Error: Message not accepted";
}
?>
If you are testing on your localhost you most likely dont have an SMTP setup. You have to setup an smtp connection for php to send the message.
I would suggest using something like phpmailer which makes it easier when working on local testing servers.
I write this code for collecting information through email, here i using sendmail plugin, but here its generated an error, that failed to connect to mail servererror
i Make little changes to php.ini
SMTP = localhost
smtp_port = 25
sendmail_path ="C:\wamp\sendmail\sendmail.exe -t -i";
<?php
$to = 'localhost,wasu3690#gmail.com';
$subject = 'My subject';
$txt = 'Hello world!';
$headers = 'From: wasu3690#gmail.com';
if (mail($to,$subject,$txt,$headers))
echo "Email Sent";
else "not sent";
ini_set("SMTP",'localhost');
ini_set("smtp_port",25);
?>
the error is:-( ! ) Warning: mail(): Failed to connect to mailserver at "ssl:smtp.gmail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in F:\wamp\www\ihbt\signup.php on line 75
Actually i am trying to send activation email but the above error is showing up. i am using wamp.
here is the code
<?php
ini_set("SMTP","ssl:smtp.gmail.com" );
$myem = "my gmail account#gmail.com";
$msg = "almost there..";
if (mail("$email", "Activate your email","$msg", "From: $myem")){
echo "Email sent";
}
else
echo "Email sending failed";
?>