Send email with PHP/IIS - php

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.

Related

PHP: Why my Mail() Functions are not working?

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

Warning: mail(): SMTP server response: 550 No such user here in C:\home\site\wwwroot\db_resp3.php on line 19

I am trying to write a simple php script to send an email. Here is my code:
<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
ini_set('sendmail_from', 'mail#leslie4stateassembly.com');
ini_set('SMTP', 'mail.leslie4stateassembly.com');
ini_set('smtp_port', 25);
$recipient= "to2240#columbia.edu";
$subject= "Example Email";
$email= "Is this message gonna send!?!?";
$headers= "From:mail#leslie4stateassembly.com";
$result = mail($recipient, $subject, $email, $headers);
if ($result == false){
echo "didn't send";
}
else {
echo "sent";
}
echo phpinfo();
?>
I'm using the GearHost.com mail servers. For some reason, I keep getting this response:
Warning: mail(): SMTP server response: 550 No such user here in C:\home\site\wwwroot\db_resp3.php on l
(for the record, I know that the recipient email address is correct.)
Please help!

php mail function Failed to connect to mail server at

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.

Authentication Required error while sending email using PHP

I am trying to send email using following PHP code.But I get the following error:
Warning: mail(): SMTP server response: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1 http://support.google.com/mail/bin/answer.py?answer=14257
<?php
$to = "jaynanavati#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "jaynanavati#gmail.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
It is pretty obvious that your SMTP server requires you to authenticate. Use a more powerful tool for sending mail, such as PHPMailer.

unable to send mail via php

I am trying to send mail using php.And i am using WampServer.
so i tried the following code
ini_set("SMTP","smtp.gmail.com" );
ini_set("smtp_port","465");
ini_set('sendmail_from', 'person1#gmail.com');
$to = "person2#gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "person1#gmail.com";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
if( $retval == true )
{
echo "Message sent successfully...";
}
else
{
echo "Message could not be sent...";
}
but it take more time to connect and says could not connect with localhost.
Please help me in solving the problem
try this configuration:
http://blog.techwheels.net/send-email-from-localhost-wamp-server-using-sendmail/
this might help.
somehow, instead of "smtp.gmail.com", for me it works with "ssl:smtp.gmail.com"
This line:
ini_set("SMTP","smtp.gmail.com" );
should be
ini_set("SMTP","ssl:smtp.gmail.com" );
Also, see this response to a similar question: Send email using the GMail SMTP server from a PHP page
You're trying to send mail from your localhost (Your PC) I guess It's not setup to send mail. Move the script to a production server and it will work

Categories