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.
Related
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 am able to send email to other emails are yahoo,hotmail,rediff but not able to send email on gmail.
Below is my code
<?php
// the message
$msg = "test text";
// send email
if(mail("myemail#gmail.com","My subject",$msg)){
echo "dsaf";
}
?>
How can I fix this issue.
Most mail services will filter out messages send by PHP mail(). Pear mail, on the other hand, allows for you to actually login to the gmail SMTP server when sending mail. This mail won't be filtered. Make sure when doing so that you alter your gmail settings to allow for less secure clients.
You have to enable SMTP relay service setting https://support.google.com/a/answer/2956491
Also check,
https://support.google.com/a/answer/176600?hl=en
Try this code.
$to = 'somemail#gmail.com';
$name = "John Doe";
$email = "john.doe#yahoo.com";
$message = "Test Message";
$subject = "Message from ".$name;
$message = $name . " ( ". $email . " ) wrote the following:" . "\n\n" . $message;
$headers = "From:" . $email;
mail($to,$subject,$message,$headers);
would anyone be able to help me with my question..I am not able to send mail using mail() in php..Here is my code:
if (isset($_POST["from"])) {
$from = $_POST["from"]; // sender
$subject = $_POST["subject"];
$message = $_POST["message"];
$message = wordwrap($message, 70);
mail("test#example.com",$subject,$message,"From: $from\n");
echo "Thank you for sending us feedback";
}
while i am running this program in localhost,output showing as "Thank you for sending us feedback" , but not getting any mail in test#example.com.
Check your php.ini cofiguration file and add the mail server config:
SMTP = server ; mail server
smtp_port = 25 ; port
sendmail_from = your#email.com ;
Or
Use PHPMailer https://github.com/PHPMailer/PHPMailer to send via gmail, yahoo or any external mail server.
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