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 : info@hdd.net.in'. "\r\n" .'Reply-To: info@hdd.net.in' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
$to="abd@domain.in";
    $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
Share on other sites

set up an email account on your server.

user PHPMailer/Swiftmailer with SMTP as true, and enter your details. (i use PHPMailer)

 

then you are sending from a real email account, and not just through mail() which some view as spammy.

Link to comment
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   = "abc@hdd.net.in";  // 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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.