How do I configure my settings to enable php to send email from my google apps account?

Asked by:
richard87 / 13 Points
Time:
2012-11-30 10:38 pm EST
Category:
Send Email From A Page
Hits:
2,117
Usually I would change my php.ini file and install sendmail but this is my first time using cpanel and I'm not sure how to go about it?

Thanks!

To ask this user for more information, please first login.

To submit an answer, please login.

ANSWERS

0

JacobN
Staff
3,713 Points
2012-11-30 11:54 pm EST
Hello richard87, and thanks for your question.

In some cases your PHP application should already have the option built in to use SMTP authentication instead of the default PHP mail() function. If this is the case then you can go ahead and simply fill in your details for your Google Apps account in that section.

If your application doesn't have this built in already, then you would need to set this up somehow in your PHP code to allow for remote SMTP connections.

A very common method used is the PHPMailer class available at:

PHPMailer - Full Featured Email Transfer Class for PHP

Then you would load up that class in your PHP script and utilize it with something along these lines:


<?php

function smtp_mail($to, $subject, $body){
require_once("class.phpmailer.php");

$smtp = new PHPMailer();

$smtp->SMTPAuth = true;
$smtp->SMTPSecure = "ssl";
$smtp->Host = "smtp.gmail.com";
$smtp->Port = 465;
$smtp->Username = "username@gmail.com";
$smtp->Password = "password";

$smtp->SetFrom("username@gmail.com", "User name");

$smtp->Subject = $subject;
$smtp->Body = $body;

$smtp->AddAddress($to);
$smtp->Send();

unset($smtp);
}

smtp_mail("recipient@domain.com", "PHP Test using SMTP", "This is a test")

?>


I hope that information answered your question. If you have any further questions at all please feel free to ask away!

- Jacob

To submit a comment on this answer, please first login.

Want to share this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Need More Help?

Help Center Search

Current Customers

Email: support@WebHostingHub.com Ticket: Submit a Support Ticket
Call: 877-595-4HUB (4482)
757-416-6627 (Intl.)
Chat: Click To Chat Now

Ask the Community

Get help with your questions from our community of like-minded hosting users and Web Hosting Hub Staff.

Not a Customer?

Get web hosting from a company that is here to help.
}