Jump to content

User authenticated Mail Function


upendra470

Recommended Posts

I have been using simple mail function for mailing but the problem is the mail client has been configured in google apps. So whenever this script runs , it sends mail to webmail but not to gmail. What kind of mail function should i use to send emails to gmail. My domain registrar told me to use user authentication mail function but i am unable to find any such function in PHP. Please provide any concrete solution.

 

 

 

<?php   
if(isset($_POST['submit'])){
         
$name	= $_POST['nameText'];
$email	= $_POST['emailText'];
$phone= $_POST['phoneText'];
$campany = $_POST['subjectText'];		
$query = $_POST['messagetText'];
$replyback = $_POST['categoryRadio'];


$headers = 'From : [email protected]'. "\r\n" .'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$to="[email protected]";
    $subject="Requirements of a client";
    	
    	if($replyback==1)
    	{
$message="Name - ".$name. "\n Company Name - " .$campany.  "\n Email - ".$email. "\n Phone No - " .$phone. "\n Query - " .$query."\nReply by Email"." ";
}
else
{
$message="Name - ".$name. "\n Company Name - " .$campany.  "\n Email - ".$email. "\n Phone No - " .$phone. "\n Query - " .$query."\nReply by Phone"." ";	
}
       


$result = mail($to, $subject, $message, $headers);
if($result){
	echo "<script type = 'text/javascript'> alert('Mail Sent. We will get back to you shortly');</script>";
}
}
?>    

Link to comment
https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/
Share on other sites

i am using this phpmailer script.

 

$body = $message;       
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "mail.hdd.net.in"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$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   = "[email protected]";  // GMAIL username
$mail->Password   = "*******";            // GMAIL password

$mail->Subject    = $subject;
$mail->MsgHTML($body);

$mail->AddAddress($to);
if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}

}
?>    

 

But it shows

SMTP -> ERROR: Failed to connect to server: Connection timed out (110)

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

mail() uses SMTP. It's not good for sending bulk email because it opens a new socket for each mail sent.

 

PHPMailer allows you to send multiple emails through a single socket before closing it. It's mostly efficiency.

 

As per your problem, you don't want to send an email that appears to be from x-domain from y-domain's SMTP server. This is usually seen as a spammy request.

 

And your username to access google's SMTP server will be your Google account and password.

 

Read here: http://lifehacker.com/111166/how-to-use-gmail-as-your-smtp-server Old post, not sure how stale the information is.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.