i am trying to send a mail through php.. i have tried through php's mail function and phpmailer() function too. but i'm not able to send it i have tried by changing settings in php.ini tooby setting port no. to 465,25 and some more settings by getting help over the net but still my mail is not working, my code
<html>
<head>
<title>PHPMailer - SMTP (Gmail) basic test</title>
</head>
<body>
<?php
date_default_timezone_set('asia/calcutta');
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$body = "testing message";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "ssl"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 465; // set the SMTP port for the GMAIL server
$mail->Username = $_POST["u"]; // GMAIL username
$mail->Password = $_POST["p"]; // GMAIL password
$mail->SetFrom($_POST["u"], 'First Last');
$mail->Subject = "hello";
$mail->MsgHTML($body);
$address = $_POST["to"];
$mail->AddAddress($address, "info");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
i have an other page taking username,password,sender's email and getting dem on dis page.and the error i am getting is something like this:
Mailer Error: The following From address failed: s********@g***l.com : MAIL not accepted from server,530,5.5.1 Authentication Required. Learn more at 530 5.5.1 https://support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 https:/support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
SMTP server error: 5.5.1 Authentication Required. Learn more at 530 5.5.1 https:/support.google.com/mail/answer/14257 sa9sm15580073pbc.18 - gsmtp
sometimes i also get an error message saying:
called mail() without being connected mailer error in php
please help me anyone.... And Thanks in advance
$mail->SMTPSecure = 'tls';
, double check the username and password. You can check the PHPMailer documentation for gmail. – Arjun Komath