upendra470 Posted September 10, 2011 Share Posted September 10, 2011 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/ Share on other sites More sharing options...
JKG Posted September 10, 2011 Share Posted September 10, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/#findComment-1267659 Share on other sites More sharing options...
redarrow Posted September 10, 2011 Share Posted September 10, 2011 (jkg) is on about the .ini file settings of php........ Quote Link to comment https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/#findComment-1267694 Share on other sites More sharing options...
upendra470 Posted September 11, 2011 Author Share Posted September 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/#findComment-1267927 Share on other sites More sharing options...
xyph Posted September 11, 2011 Share Posted September 11, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246826-user-authenticated-mail-function/#findComment-1268064 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.