Send email using the GMail SMTP server from a PHP page
I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:
authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]
Can anyone help? Here is my code:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
php email smtp gmail
add a comment |
I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:
authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]
Can anyone help? Here is my code:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
php email smtp gmail
add a comment |
I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:
authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]
Can anyone help? Here is my code:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
php email smtp gmail
I am trying to send an email via GMail's SMTP server from a PHP page, but I get this error:
authentication failure [SMTP: SMTP server does no support authentication (code: 250, response: mx.google.com at your service, [98.117.99.235] SIZE 35651584 8BITMIME STARTTLS ENHANCEDSTATUSCODES PIPELINING)]
Can anyone help? Here is my code:
<?php
require_once "Mail.php";
$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,nnHow are you?";
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
php email smtp gmail
php email smtp gmail
edited Jun 27 '14 at 23:30
user456814
asked Apr 3 '09 at 2:47
skbskb
11.9k2982133
11.9k2982133
add a comment |
add a comment |
13 Answers
13
active
oldest
votes
// Pear Mail Library
require_once "Mail.php";
$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
132
what isMail.php
?? where do I get this file from?
– Zain Shaikh
Nov 26 '10 at 23:23
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
|
show 21 more comments
Using Swift mailer, it is quite easy to send a mail through Gmail credentials:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('abc@example.com' => 'ABC'))
->setTo(array('xyz@test.com'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
|
show 3 more comments
Your code does not appear to be using TLS (SSL), which is necessary to deliver mail to Google (and using ports 465 or 587).
You can do this by setting
$host = "ssl://smtp.gmail.com";
Your code looks suspiciously like this example which refers to ssl:// in the hostname scheme.
add a comment |
I don't recommend Pear Mail. It has not been updated since 2010. Also read the source files; the source code is almost outdated, written in PHP 4 style and many errors / bugs have been posted (Google it). I am using Swift Mailer.
Swift Mailer integrates into any web application written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.
Send emails using SMTP, sendmail, postfix or a custom Transport
implementation of your own.
Support servers that require username & password and/or encryption.
Protect from header injection attacks without stripping request data
content.
Send MIME compliant HTML/multipart emails.
Use event-driven plugins to customize the library.
Handle large attachments and inline/embedded images with low memory
use.
It is a free and open source you can Download Swift Mailer and upload to your server. (The feature list is copied from owner website).
The working example of Gmail SSL/SMTP and Swift Mailer is here...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
I hope this helps. Happy coding... :)
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
add a comment |
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // 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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('contact@prsps.in', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "user2@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
add a comment |
SwiftMailer can send E-Mail using external servers.
here is an example that shows how to use a Gmail server:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
add a comment |
The code as listed in the question needs two changes
$host = "ssl://smtp.gmail.com";
$port = "465";
Port 465 is required for an SSL connection.
add a comment |
Send Mail using phpMailer library through Gmail
Please donwload library files from Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$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";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
add a comment |
Gmail requires port 465, and also it's the code from phpmailer :)
add a comment |
I had this problem also. I set the correct settings and have enabled less secure apps but it still did not work. Finally, I enabled this https://accounts.google.com/UnlockCaptcha, and it worked for me. I hope this helps someone.
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
add a comment |
To install PEAR's Mail.php in Ubuntu, run following set of commands:
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
add a comment |
I have a solution for GSuite accounts that doesnt have the "@gmail.com" sufix. Also I think it will work for GSuite accounts with the @gmail.com but havent tried it.
First you should have the privileges to change the option "allos¿w less secure app" for your GSuite account. If you have the privileges (you can check in account settings->security) then you have to deactivate "two step factor authentication" go to the end of the page and set to "yes" for allow less secure applications. That's all. If you dont have privileges to change those options the solution for this thread will not work. Check https://support.google.com/a/answer/6260879?hl=en to make changes to "allow less..." option.
add a comment |
Set
'auth' => false,
Also, see if port 25 works.
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
add a comment |
protected by Bill the Lizard Aug 30 '10 at 11:14
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
13 Answers
13
active
oldest
votes
13 Answers
13
active
oldest
votes
active
oldest
votes
active
oldest
votes
// Pear Mail Library
require_once "Mail.php";
$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
132
what isMail.php
?? where do I get this file from?
– Zain Shaikh
Nov 26 '10 at 23:23
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
|
show 21 more comments
// Pear Mail Library
require_once "Mail.php";
$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
132
what isMail.php
?? where do I get this file from?
– Zain Shaikh
Nov 26 '10 at 23:23
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
|
show 21 more comments
// Pear Mail Library
require_once "Mail.php";
$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
// Pear Mail Library
require_once "Mail.php";
$from = '<fromaddress@gmail.com>';
$to = '<toaddress@yahoo.com>';
$subject = 'Hi!';
$body = "Hi,nnHow are you?";
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe@gmail.com',
'password' => 'passwordxxx'
));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo('<p>' . $mail->getMessage() . '</p>');
} else {
echo('<p>Message successfully sent!</p>');
}
edited Jan 14 '16 at 2:06
Nathan Tuggy
2,18592535
2,18592535
answered May 1 '10 at 4:02
pavan kumarpavan kumar
3,4921112
3,4921112
132
what isMail.php
?? where do I get this file from?
– Zain Shaikh
Nov 26 '10 at 23:23
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
|
show 21 more comments
132
what isMail.php
?? where do I get this file from?
– Zain Shaikh
Nov 26 '10 at 23:23
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
132
132
what is
Mail.php
?? where do I get this file from?– Zain Shaikh
Nov 26 '10 at 23:23
what is
Mail.php
?? where do I get this file from?– Zain Shaikh
Nov 26 '10 at 23:23
77
77
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
He's using the Pear Mail package.
– Xavi
Dec 14 '10 at 1:19
18
18
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
could anyone please give me a link where I can get the Mail.php file. Because I tried it and it would not work Thanks
– Yoosuf
Apr 17 '11 at 6:52
11
11
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
Where are the @ symbols in this example above? I do not see a single one in there!
– darkAsPitch
Jun 30 '11 at 4:08
6
6
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
I believe that myaccount.gmail.com is the same as myaccount@gmail.com in the email standards.
– Sherwin Flight
Oct 14 '11 at 9:02
|
show 21 more comments
Using Swift mailer, it is quite easy to send a mail through Gmail credentials:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('abc@example.com' => 'ABC'))
->setTo(array('xyz@test.com'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
|
show 3 more comments
Using Swift mailer, it is quite easy to send a mail through Gmail credentials:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('abc@example.com' => 'ABC'))
->setTo(array('xyz@test.com'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
|
show 3 more comments
Using Swift mailer, it is quite easy to send a mail through Gmail credentials:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('abc@example.com' => 'ABC'))
->setTo(array('xyz@test.com'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
Using Swift mailer, it is quite easy to send a mail through Gmail credentials:
<?php
require_once 'swift/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('GMAIL_USERNAME')
->setPassword('GMAIL_PASSWORD');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test Subject')
->setFrom(array('abc@example.com' => 'ABC'))
->setTo(array('xyz@test.com'))
->setBody('This is a test mail.');
$result = $mailer->send($message);
?>
edited May 15 '13 at 5:34
answered Sep 7 '12 at 12:10
shasi kanthshasi kanth
4,2351886142
4,2351886142
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
|
show 3 more comments
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
2
2
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
This worked "to the first" just changing the GMAIL_USERNAME, GMAIL_PASSWORD, and the From and To addresses. No other solution worked for me. Thanks.
– Marco Muciño
May 14 '13 at 18:08
7
7
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
I agree, swift mailer is a drop in mail solution that much easier than messing with pear. Don't forget to enable PHP's php_openssl extension.
– Soth
May 30 '13 at 4:02
1
1
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
Nice solution using SwiftMailer! +1
– Amal Murali
Feb 16 '14 at 6:16
1
1
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
arrrgh. icant get swiftmailer to work. i dont know how to use that "composer" so i just downloaded the swiftmailer zip from github then I enabled open_ssl then supplied my gmail email and password but it still didnt work.
– boi_echos
Sep 14 '14 at 13:05
3
3
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
ah sorry for my stupidity. you have to open your gmail account because there is an email telling you to enable "less secure app". then its now working heheh
– boi_echos
Sep 14 '14 at 13:09
|
show 3 more comments
Your code does not appear to be using TLS (SSL), which is necessary to deliver mail to Google (and using ports 465 or 587).
You can do this by setting
$host = "ssl://smtp.gmail.com";
Your code looks suspiciously like this example which refers to ssl:// in the hostname scheme.
add a comment |
Your code does not appear to be using TLS (SSL), which is necessary to deliver mail to Google (and using ports 465 or 587).
You can do this by setting
$host = "ssl://smtp.gmail.com";
Your code looks suspiciously like this example which refers to ssl:// in the hostname scheme.
add a comment |
Your code does not appear to be using TLS (SSL), which is necessary to deliver mail to Google (and using ports 465 or 587).
You can do this by setting
$host = "ssl://smtp.gmail.com";
Your code looks suspiciously like this example which refers to ssl:// in the hostname scheme.
Your code does not appear to be using TLS (SSL), which is necessary to deliver mail to Google (and using ports 465 or 587).
You can do this by setting
$host = "ssl://smtp.gmail.com";
Your code looks suspiciously like this example which refers to ssl:// in the hostname scheme.
answered Apr 3 '09 at 3:00
crbcrb
7,11563346
7,11563346
add a comment |
add a comment |
I don't recommend Pear Mail. It has not been updated since 2010. Also read the source files; the source code is almost outdated, written in PHP 4 style and many errors / bugs have been posted (Google it). I am using Swift Mailer.
Swift Mailer integrates into any web application written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.
Send emails using SMTP, sendmail, postfix or a custom Transport
implementation of your own.
Support servers that require username & password and/or encryption.
Protect from header injection attacks without stripping request data
content.
Send MIME compliant HTML/multipart emails.
Use event-driven plugins to customize the library.
Handle large attachments and inline/embedded images with low memory
use.
It is a free and open source you can Download Swift Mailer and upload to your server. (The feature list is copied from owner website).
The working example of Gmail SSL/SMTP and Swift Mailer is here...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
I hope this helps. Happy coding... :)
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
add a comment |
I don't recommend Pear Mail. It has not been updated since 2010. Also read the source files; the source code is almost outdated, written in PHP 4 style and many errors / bugs have been posted (Google it). I am using Swift Mailer.
Swift Mailer integrates into any web application written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.
Send emails using SMTP, sendmail, postfix or a custom Transport
implementation of your own.
Support servers that require username & password and/or encryption.
Protect from header injection attacks without stripping request data
content.
Send MIME compliant HTML/multipart emails.
Use event-driven plugins to customize the library.
Handle large attachments and inline/embedded images with low memory
use.
It is a free and open source you can Download Swift Mailer and upload to your server. (The feature list is copied from owner website).
The working example of Gmail SSL/SMTP and Swift Mailer is here...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
I hope this helps. Happy coding... :)
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
add a comment |
I don't recommend Pear Mail. It has not been updated since 2010. Also read the source files; the source code is almost outdated, written in PHP 4 style and many errors / bugs have been posted (Google it). I am using Swift Mailer.
Swift Mailer integrates into any web application written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.
Send emails using SMTP, sendmail, postfix or a custom Transport
implementation of your own.
Support servers that require username & password and/or encryption.
Protect from header injection attacks without stripping request data
content.
Send MIME compliant HTML/multipart emails.
Use event-driven plugins to customize the library.
Handle large attachments and inline/embedded images with low memory
use.
It is a free and open source you can Download Swift Mailer and upload to your server. (The feature list is copied from owner website).
The working example of Gmail SSL/SMTP and Swift Mailer is here...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
I hope this helps. Happy coding... :)
I don't recommend Pear Mail. It has not been updated since 2010. Also read the source files; the source code is almost outdated, written in PHP 4 style and many errors / bugs have been posted (Google it). I am using Swift Mailer.
Swift Mailer integrates into any web application written in PHP 5, offering a flexible and elegant object-oriented approach to sending emails with a multitude of features.
Send emails using SMTP, sendmail, postfix or a custom Transport
implementation of your own.
Support servers that require username & password and/or encryption.
Protect from header injection attacks without stripping request data
content.
Send MIME compliant HTML/multipart emails.
Use event-driven plugins to customize the library.
Handle large attachments and inline/embedded images with low memory
use.
It is a free and open source you can Download Swift Mailer and upload to your server. (The feature list is copied from owner website).
The working example of Gmail SSL/SMTP and Swift Mailer is here...
// Swift Mailer Library
require_once '../path/to/lib/swift_required.php';
// Mail Transport
$transport = Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465)
->setUsername('username@gmail.com') // Your Gmail Username
->setPassword('my_secure_gmail_password'); // Your Gmail Password
// Mailer
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject Here')
->setFrom(array('sender@example.com' => 'Sender Name')) // can be $_POST['email'] etc...
->setTo(array('receiver@example.com' => 'Receiver Name')) // your email / multiple supported.
->setBody('Here is the <strong>message</strong> itself. It can be text or <h1>HTML</h1>.', 'text/html');
// Send the message
if ($mailer->send($message)) {
echo 'Mail sent successfully.';
} else {
echo 'I am sure, your configuration are not correct. :(';
}
I hope this helps. Happy coding... :)
edited Apr 9 '14 at 0:37
Peter Mortensen
13.7k1986113
13.7k1986113
answered Aug 2 '13 at 16:42
Madan SapkotaMadan Sapkota
16.7k683100
16.7k683100
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
add a comment |
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
1
1
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
This no longer works, I always get the return message "535-5.7.8 Username and Password not accepted". My credentials are fine and I have set the "allow less-secure apps" to ON. Anyone know a fix to this?
– AndrewB
May 17 '17 at 17:08
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
Swift doesn't seem to work in PHP 5.x - doesn't understand the ?? coalesce - just blows up.
– HerrimanCoder
Jan 5 '18 at 4:51
add a comment |
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // 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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('contact@prsps.in', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "user2@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
add a comment |
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // 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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('contact@prsps.in', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "user2@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
add a comment |
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // 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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('contact@prsps.in', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "user2@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
<?php
date_default_timezone_set('America/Toronto');
require_once('class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail = new PHPMailer();
$body = "gdssdh";
//$body = eregi_replace("[]",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
//$mail->Host = "ssl://smtp.gmail.com"; // SMTP server
$mail->SMTPDebug = 1; // 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 = "user@gmail.com"; // GMAIL username
$mail->Password = "password"; // GMAIL password
$mail->SetFrom('contact@prsps.in', 'PRSPS');
//$mail->AddReplyTo("user2@gmail.com', 'First Last");
$mail->Subject = "PRSPS password";
//$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "user2@yahoo.co.in";
$mail->AddAddress($address, "user2");
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
edited Mar 23 '16 at 7:24
answered Dec 25 '11 at 12:19
Deept RaghavDeept Raghav
1,2281214
1,2281214
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
add a comment |
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
Why do you set the host twice and which one is the right one?
– Emile Bergeron
Mar 9 '16 at 3:13
1
1
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
I have edited the answer. Happy Coding :)
– Deept Raghav
Mar 23 '16 at 7:25
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
Where do I get the class.phpmailer.php file?? Pasting code only is not so helpful pls include more description on the code too!
– GeneCode
Jan 24 '18 at 1:54
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
While some of the syntax is outdated, PHPMailer ended up being the best solution for me, +1
– zoltar
Mar 15 '18 at 0:43
add a comment |
SwiftMailer can send E-Mail using external servers.
here is an example that shows how to use a Gmail server:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
add a comment |
SwiftMailer can send E-Mail using external servers.
here is an example that shows how to use a Gmail server:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
add a comment |
SwiftMailer can send E-Mail using external servers.
here is an example that shows how to use a Gmail server:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
SwiftMailer can send E-Mail using external servers.
here is an example that shows how to use a Gmail server:
require_once "lib/Swift.php";
require_once "lib/Swift/Connection/SMTP.php";
//Connect to localhost on port 25
$swift =& new Swift(new Swift_Connection_SMTP("localhost"));
//Connect to an IP address on a non-standard port
$swift =& new Swift(new Swift_Connection_SMTP("217.147.94.117", 419));
//Connect to Gmail (PHP5)
$swift = new Swift(new Swift_Connection_SMTP(
"smtp.gmail.com", Swift_Connection_SMTP::PORT_SECURE, Swift_Connection_SMTP::ENC_TLS));
edited May 20 '16 at 8:17
Sam Apostel
458214
458214
answered Dec 23 '10 at 14:57
Pekka 웃Pekka 웃
359k1188431014
359k1188431014
add a comment |
add a comment |
The code as listed in the question needs two changes
$host = "ssl://smtp.gmail.com";
$port = "465";
Port 465 is required for an SSL connection.
add a comment |
The code as listed in the question needs two changes
$host = "ssl://smtp.gmail.com";
$port = "465";
Port 465 is required for an SSL connection.
add a comment |
The code as listed in the question needs two changes
$host = "ssl://smtp.gmail.com";
$port = "465";
Port 465 is required for an SSL connection.
The code as listed in the question needs two changes
$host = "ssl://smtp.gmail.com";
$port = "465";
Port 465 is required for an SSL connection.
answered Apr 16 '10 at 1:50
s01ipsists01ipsist
2,29212332
2,29212332
add a comment |
add a comment |
Send Mail using phpMailer library through Gmail
Please donwload library files from Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$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";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
add a comment |
Send Mail using phpMailer library through Gmail
Please donwload library files from Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$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";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
add a comment |
Send Mail using phpMailer library through Gmail
Please donwload library files from Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$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";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
Send Mail using phpMailer library through Gmail
Please donwload library files from Github
<?php
/**
* This example shows settings to use when sending via Google's Gmail servers.
*/
//SMTP needs accurate times, and the PHP time zone MUST be set
//This should be done in your php.ini, but this is how to do it if you don't have access to that
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$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";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
answered Sep 26 '16 at 10:17
Bhavin SolankiBhavin Solanki
1,164923
1,164923
add a comment |
add a comment |
Gmail requires port 465, and also it's the code from phpmailer :)
add a comment |
Gmail requires port 465, and also it's the code from phpmailer :)
add a comment |
Gmail requires port 465, and also it's the code from phpmailer :)
Gmail requires port 465, and also it's the code from phpmailer :)
edited Apr 9 '14 at 0:26
Peter Mortensen
13.7k1986113
13.7k1986113
answered Jul 11 '09 at 21:26
sandeep
add a comment |
add a comment |
I had this problem also. I set the correct settings and have enabled less secure apps but it still did not work. Finally, I enabled this https://accounts.google.com/UnlockCaptcha, and it worked for me. I hope this helps someone.
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
add a comment |
I had this problem also. I set the correct settings and have enabled less secure apps but it still did not work. Finally, I enabled this https://accounts.google.com/UnlockCaptcha, and it worked for me. I hope this helps someone.
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
add a comment |
I had this problem also. I set the correct settings and have enabled less secure apps but it still did not work. Finally, I enabled this https://accounts.google.com/UnlockCaptcha, and it worked for me. I hope this helps someone.
I had this problem also. I set the correct settings and have enabled less secure apps but it still did not work. Finally, I enabled this https://accounts.google.com/UnlockCaptcha, and it worked for me. I hope this helps someone.
answered Oct 25 '16 at 10:56
StrategistStrategist
396610
396610
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
add a comment |
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
1
1
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
This works, thankyou
– pokeybit
Jan 31 '18 at 12:09
add a comment |
To install PEAR's Mail.php in Ubuntu, run following set of commands:
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
add a comment |
To install PEAR's Mail.php in Ubuntu, run following set of commands:
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
add a comment |
To install PEAR's Mail.php in Ubuntu, run following set of commands:
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
To install PEAR's Mail.php in Ubuntu, run following set of commands:
sudo apt-get install php-pear
sudo pear install mail
sudo pear install Net_SMTP
sudo pear install Auth_SASL
sudo pear install mail_mime
answered Apr 11 '17 at 11:08
NahidNahid
1,61611213
1,61611213
add a comment |
add a comment |
I have a solution for GSuite accounts that doesnt have the "@gmail.com" sufix. Also I think it will work for GSuite accounts with the @gmail.com but havent tried it.
First you should have the privileges to change the option "allos¿w less secure app" for your GSuite account. If you have the privileges (you can check in account settings->security) then you have to deactivate "two step factor authentication" go to the end of the page and set to "yes" for allow less secure applications. That's all. If you dont have privileges to change those options the solution for this thread will not work. Check https://support.google.com/a/answer/6260879?hl=en to make changes to "allow less..." option.
add a comment |
I have a solution for GSuite accounts that doesnt have the "@gmail.com" sufix. Also I think it will work for GSuite accounts with the @gmail.com but havent tried it.
First you should have the privileges to change the option "allos¿w less secure app" for your GSuite account. If you have the privileges (you can check in account settings->security) then you have to deactivate "two step factor authentication" go to the end of the page and set to "yes" for allow less secure applications. That's all. If you dont have privileges to change those options the solution for this thread will not work. Check https://support.google.com/a/answer/6260879?hl=en to make changes to "allow less..." option.
add a comment |
I have a solution for GSuite accounts that doesnt have the "@gmail.com" sufix. Also I think it will work for GSuite accounts with the @gmail.com but havent tried it.
First you should have the privileges to change the option "allos¿w less secure app" for your GSuite account. If you have the privileges (you can check in account settings->security) then you have to deactivate "two step factor authentication" go to the end of the page and set to "yes" for allow less secure applications. That's all. If you dont have privileges to change those options the solution for this thread will not work. Check https://support.google.com/a/answer/6260879?hl=en to make changes to "allow less..." option.
I have a solution for GSuite accounts that doesnt have the "@gmail.com" sufix. Also I think it will work for GSuite accounts with the @gmail.com but havent tried it.
First you should have the privileges to change the option "allos¿w less secure app" for your GSuite account. If you have the privileges (you can check in account settings->security) then you have to deactivate "two step factor authentication" go to the end of the page and set to "yes" for allow less secure applications. That's all. If you dont have privileges to change those options the solution for this thread will not work. Check https://support.google.com/a/answer/6260879?hl=en to make changes to "allow less..." option.
answered Sep 1 '18 at 15:20
Diego Andrés Díaz EspinozaDiego Andrés Díaz Espinoza
430710
430710
add a comment |
add a comment |
Set
'auth' => false,
Also, see if port 25 works.
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
add a comment |
Set
'auth' => false,
Also, see if port 25 works.
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
add a comment |
Set
'auth' => false,
Also, see if port 25 works.
Set
'auth' => false,
Also, see if port 25 works.
answered Apr 3 '09 at 2:57
CookieOfFortuneCookieOfFortune
11.4k42754
11.4k42754
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
add a comment |
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
2
2
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
It won't - Google requires delivery on 465 or 587. See mail.google.com/support/bin/answer.py?hl=en&answer=13287.
– crb
Apr 3 '09 at 3:11
add a comment |
protected by Bill the Lizard Aug 30 '10 at 11:14
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?