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
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 = "email@example.com"; // Password to use for SMTP authentication $mail->Password = "yourpassword";
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 = "firstname.lastname@example.org"; $mail->Password = "yourpassword";
There is a tutorial at https://github.com/PHPMailer/PHPMailer/wiki/Tutorial and examples at https://github.com/PHPMailer/PHPMailer/tree/master/examples