Mobile app version of vmapp.org
Login or Join
Smith883

: How can i send email in php through google apps My client is using godaddy to host a php site, and has recently signed up for google apps account for email, hoping it will help stop his

@Smith883

Posted in: #Email #Godaddy #GoogleApps #Php

My client is using godaddy to host a php site, and has recently signed up for google apps account for email, hoping it will help stop his automated emails from getting rejected as spam. The code sends emails using the phpmailer class. What changes do I need to make so that the email will be sent out through google instead of through godaddy? Is it a code change? Or do I need to set up mx records somewhere? How can I tell which server is actually sending the email

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Smith883

2 Comments

Sorted by latest first Latest Oldest Best

 

@BetL925

MX Record will not automatically send email from your server. You need to make some CODE change. Check this answer if you want to do it with PHPMailer.

$mail = new PHPMailer;
// Tell PHPMailer to use SMTP
$mail->isSMTP();
// Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
// Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
// Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
// use
// $mail->Host = gethostbyname('smtp.gmail.com');
// if your network does not support SMTP over IPv6
// Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
$mail->Port = 587;
// Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
// Whether to use SMTP authentication
$mail->SMTPAuth = true;
// Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "username@gmail.com";
// Password to use for SMTP authentication
$mail->Password = "yourpassword";


However, that solution has some problems of its own. The best way is to properly setup your mail server using DKIM and other settings, so that your emails don't go to spam.

10% popularity Vote Up Vote Down


 

@Pierce454

In the code somewhere, you can set many variables that PHPmailer is going to use. This includes explicitly naming the mail server.

Your code may include something like

$mail->isSMTP();
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->Username = "yourname@example.com";
$mail->Password = "yourpassword";


There is a tutorial at github.com/PHPMailer/PHPMailer/wiki/Tutorial and examples at github.com/PHPMailer/PHPMailer/tree/master/examples

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme