Send mail from gmail

thuron

New member
Joined
May 23, 2011
Messages
4
Since I moved my site to DirectAdmin my contact forms do not send mail anymore. When I set the mail host and port to Gmail, it sais it cannot connect to the SMTP host, and when I do not set the host and port, it sends the mail from DirectAdmin, but I need my scripts to send it from Google Apps/Gmail. is there some port I need to open in DirectAdmin?

Kind regards,

Thuron
 
How exactly did you set the mail host and port to gmail? You should be setting the mx records in dns administration and unchecking the box to host mail locally.
 
The first mistake I made was that I did not uncheck the box :o
For the mailing I'm using PHPMailer, and I set the host and port like this:

$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;

I don't know how long it could take for the MX Record to take effect, but I hope this works soon.
 
I just checked again and it still says "SMTP Error: Could not connect to SMTP host." I rechecked the MX Records and the Host + port in my script and everything seems to be fine... Does anyone have any idea why it is not working? This is the script i'm using:

PHP:
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "ssl://smtp.gmail.com"; // specify main and backup server
$mail->Port = 465; // set the port to use 
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // your SMTP username or your gmail username
$mail->Password = "password"; // your SMTP password or your gmail password
$mail->From = $email;
$mail->FromName = $name ." using Contact Form"; // Name to indicate where the email came from when the recepient received
$mail->AddAddress("[email protected]", "Contact Form");
$mail->AddReplyTo($email, $name);
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = $subject2;
$mail->Body = "Type:" . $type . "<br /> <br /> " . $message; //HTML Body
$mail->AltBody = $message; //Text Body
 
Did the documentation say to use ssl:// ? I would remove that if not it doesnt seem right at all.

You can test to see if the port opens by using this ssh command:

Code:
openssl s_client -connect smtp.gmail.com:465

That would at least tell you if its able to make a connection outbound. If not then you know there might be some firewall blocking the connection.

I just looked up the docs and it says to use the following:

Code:
$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
[COLOR="Red"]$mail->SMTPSecure = "ssl"; [/COLOR]                // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port

Look in the doc folder of phpmailer there is a guide to using gmail server.
 
Last edited:
I checked the doc, got one of the scripts for gmail in my scripts and edited the email addresses and password. Got this:

PHP:
SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 
SMTP Error: Could not connect to SMTP host.

A question about the command you posted: Where should I enter it?:o

kind regards,

Thuron
 
It shouldnt be using port 110.

Make sure you entered the those lines like I posted above.

You can enter the openssl command in your ssh connection.

If your hosting provider didnt give you ssh access then you wont be able to test it.

Here is the entire help file for using gmail:

Code:
<?php

// example on using PHPMailer with GMAIL

include("class.phpmailer.php");
include("class.smtp.php"); // note, this is optional - gets called from main class if not already loaded

$mail             = new PHPMailer();

$body             = $mail->getFile('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->IsSMTP();
$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

$mail->Username   = "[email protected]";  // GMAIL username
$mail->Password   = "password";            // GMAIL password

$mail->From       = "[email protected]";
$mail->FromName   = "Webmaster";
$mail->Subject    = "This is the subject";
$mail->AltBody    = "This is the body when user views in plain text format"; //Text Body
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddReplyTo("[email protected]","Webmaster");

$mail->AddAttachment("/path/to/file.zip");             // attachment
$mail->AddAttachment("/path/to/image.jpg", "new.jpg"); // attachment

$mail->AddAddress("[email protected]","First Last");

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message has been sent";
}

?>
 
Last edited:
Try disable Firewall, it will work
I have problem sending email . I use smtp.gmail.com to send mail for registration/feedback....
Howerver it doesn't work. Try disable Firewall Security & Firewall - csf then it works.
Anyone can help. I need both, sending email and Firewall
Thanks
 
Back
Top