I have installed WAMP Server on my Windows 10 PC and when I try to send emails through a valid SMTP configuration it doesn't work. The same SMTP configuration works on another LAMP installation and also on a live server.
When I try sending the email through a PrestaShop installation I get following error:
Error: Please check your configuration
Connection could not be established with host smtp.gmail.com [ #0]
And with Magento I get following error:
SMTP Pro Self Test Results
Sending test email to your contact form address: xxxxxxx#example.com from: xxx.adsxx#example.com. Unable to send test email.
Exception message was: Could not open socket
Please check the user guide for frequent error messages and their solutions.
Default templates exist.
Email communications are enabled.
As per my understanding, this issue is not dependent on Magento or PrestaShop, it is coming because of the WAMP installation.
Do I have to enable some extension or something for the WAMP installation? Or have I missed something else?
Please help. Already wasted a lot of time investigating and trying solutions from the Web, but nothing seems to be working.
Download the sendmail.zip
Create a folder named “sendmail” in “C:\wamp\”.
Extract these 4 files in “sendmail” folder: “sendmail.exe”, “libeay32.dll”, “ssleay32.dll” and “sendmail.ini”.
Open the “sendmail.ini” file and configure it as following
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
default_domain=localhost
error_logfile=error.log
debug_logfile=debug.log
auth_username=[your_gmail_account_username]#gmail.com
auth_password=[your_gmail_account_password]
pop3_server=
pop3_username=
pop3_password=
force_sender=
force_recipient=
hostname=localhost
You do not need to specify any value for these properties: pop3_server, pop3_username, pop3_password, force_sender, force_recipient. The error_logfile and debug_logfile settings should be kept blank if you have already sent successful email(s) otherwise size of this file will keep increasing. Enable these log file settings if you don’t get able to send email using sendmail.
Enable IMAP Access in your GMail’s Settings -> Forwarding and POP/IMAP -> IMAP Access:
Enable “php_openssl” and “php_sockets” extensions for PHP compiler:
Open php.ini from “C:\wamp\bin\apache\Apache2.2.17\bin” and configure it as following (The php.ini at “C:\wamp\bin\php\php5.3.x” would not work) (You just need to configure the last line in the following code, prefix semicolon (;) against other lines):
Restart WAMP Server.
Create a PHP file and write the following code in it:
<?php
$to = 'recipient#yahoo.com';
$subject = 'Testing sendmail.exe';
$message = 'Hi, you just received an email using sendmail!';
$headers = 'From: [your_gmail_account_username]#gmail.com' . "\r\n" .
'MIME-Version: 1.0' . "\r\n" .
'Content-type: text/html; charset=utf-8';
if(mail($to, $subject, $message, $headers))
echo "Email sent";
else
echo "Email sending failed";
?>
Make appropriate changes in $to and $headers variables to set recipient and sender (“From” header) addresses. Save it as “send-mail.php”. (You can save it anywhere or inside any sub-folder in “C:\wamp\www”.)
Open this file in browser, it MUST work now
These are possibly causes which prevent you from sending mails via WAMP server.
Your firewall configurations may (by default) block some ports used by WAMP for sending emails.
These ports may be already used by your others applications. Prefer to this to know which port is being used by which application.
Administrators rights are required for the WAMP server to be able to send mail. Run the server as administrator.
Since you're sure that settings have already worked on a server so I assume there nothing to check with PHP.ini
make sure that your -
extension=php_openssl.dll
extension=php_sockets.dll
is enable in php.ini file.
check is Enable ssl_module under Apache Module.
You can use PHP Mailer or Download php mailer with example from here. Once you setup the phpmailer with your project use following code to send mail using gmail SMTP :
require_once('inc/class.phpmailer.php'); # INCLUDE PHPMailer CLASS FILE
require_once("inc/class.smtp.php"); # INCLUDE OTHER SMTP FILE
Include above files in your project or PHP file which you use to send email and then :
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 0; # ENABLE SMTP DEBUG INFORMATION (FOR TESTING)
# 1 = ERROR AND MESSAGE
# 2 = MESSAGE ONLY
$mail->SMTPAuth = true; # ENABLE SMTP AUTHENTICATION
$mail->Host = "Host Addresss"; # smtp.gmail.com
$mail->Port = 587; # PORT NUMBER
$mail->Username = "example#gmail.com"; # SMTP EMAIL USER NAME
$mail->Password = "xxxxxxx"; # SMTP ACCOUNT PASSWORD
$mail->SetFrom('example#gmail.com', 'Test Name');
$mail->SMTPSecure = 'tls';
$mail->AddReplyTo("example#gmail.com","SMTP TEST");
$v_Msg ="This is a test message via SMTP";
$mail->Subject = "EMAIL SUBJECT";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; # OPTIONAL
$address = "sendto#email.com"; # ADDRESS WHERE YOU WANT TO SEND MAIL
$mail->AddAddress($address, "TESTING");
$mail->MsgHTML($v_Msg); # EMAIL CONTENT
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo; # ERROR MESSAGE, IF MAIL NOT SENT SUCCESSFULLY
}else {
echo "Message sent!"; # SUCCESS MESSAGE
}
NOTE : Make sure your smtp gmail account must be Allow less secure apps: ON. You can turn on less secure apps for your gmail
account using THIS URL
Sometimes its easier not to rely on your own smtp server. (firewalls everywhere)
You can experiment with some other online mail delivery services than gmail, like mailgun or sendgrid.
Related
I have installed wamp on windows 8.
Got error:
Warning: mail() [function.mail]: Failed to connect to mailserver at
"localhost" port 25, verify your "SMTP" and "smtp_port" setting in
php.ini or use ini_set() in C:\wamp\www\mail.php on line 9
Here is the simple source code:
<?php
// The message
$message = "Line 1\r\nLine 2\r\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70, "\r\n");
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
Which software do i have to install to email through php on windows 8? sendmail, msmtp or ssmtp?
Try this
Configure This Setups
in php.ini
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id#gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
in sendmail.ini:
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=my-gmail-id#gmail.com
auth_password=my-gmail-password
force_sender=my-gmail-id#gmail.com
Important: comment following line if there is another sendmail_path in the php.ini : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
Note: Tested and works fine in my Windows 8.1
Possible solution. See this question
For me configuring a mail client on localhost is quite difficult. I also tried quite a few times. Later I moved on to other solutions.
You can use SwiftMailer or PhpMailer with some configuration or you can try this tool with zero configuration.
On a side note, if you are using your windows PC for development and not as a production server, then I suggest that you don't bother setting up a sendmail in windows, just use this handy tool.
Test Mail Server Tool (Its Free)
It will emulate an email server and once any script tries to send an email, it will intercept it and open it for you as an .eml file, which you can open up in any email reader like outlook or mail viewer(again its free).
Now setting this tool up is just a breez, and you will thank me later for all the time that you saved, from not having to manually setup the sendmail, which I must mention is meant to be on a linux machine. ;)
I'd recommend mercury (http://www.pmail.com/downloads_s3_t.htm - Mercury/32 Mail Transport System for Win32 and NetWare Systems v4.74).
This is included in XAMPP, fairly easy to set up and you don't need to configure or (ab)use an email account. You can see the whole smtp transaction in mercury mail log window.
Look here for an excellent answer on how to setup mailing from php: PHP mail form doesn't complete sending e-mail
Use this function tool:
https://github.com/PHPMailer/PHPMailer
Mail() is prette dificult to use and this function allows you to use the email servers STMP function to send emails.
Read documentation here:
https://github.com/PHPMailer/PHPMailer/blob/master/README.md
You need to use email server along with php.
https://www.hmailserver.com/
When you are using an e-mail sender functionality through a server that requires SMTP
Authentication, you must need to specify it. And set the host, username and
password (and maybe the port if it is not the default one - 25).
For example, I usually use PHPMailer with similar settings to this ones:
//ini settings
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "YOURMAIL#gmail.com");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';
$mail->Host = "mail.example.com"; // SMTP server example
$mail->SMTPDebug = 0; // enables SMTP debug information (for testing)
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP port for the GMAIL server
$mail->Username = "username"; //Your SMTP account username example
$mail->Password = "password"; //Your SMTP account password example
You can find more about PHPMailer here.
You can video ride for how SMTP configure on wondows here.
I am using localhost WAMP server (Windows) for webhosting. I am getting the following error.
phpmailer ERROR :Could not instantiate mail function.
I have tried many solutions but nothing worked for me.
PHP mailing script
$mailer = new PHPMailer();
$mailer->IsMAIL();
$mailer->CharSet = 'utf-8';
$mailer->AddAddress($formvars['email'],$formvars['name']);
$mailer->Subject = "Your registration with ".$this->sitename;
$mailer->From = $this->GetFromAddress();
$confirmcode = $formvars['confirmcode'];
$confirm_url = $this->GetAbsoluteURLFolder().'/confirmreg.php?code='.$confirmcode;
$mailer->Body ="Hello ".$formvars['name']."\r\n\r\n".
"Thanks for your registration with ".$this->sitename."\r\n".
"Please click the link below to confirm your registration.\r\n".
"$confirm_url\r\n".
"\r\n".
"Regards,\r\n".
"Webmaster\r\n".
$this->sitename;
if(!$mailer->Send())
{
$this->HandleError("Failed sending registration confirmation email.".$mailer->ErrorInfo);
//echo "Mailer Error: " . $mailer->ErrorInfo;
return false;
}
return true;
How do I diagnose this error?
$mailer->IsMAIL(); tells PHPMailer to use the PHP mail() function for emails delivery. It works out of the box on Unix-like OSes but not on Windows because the desktop versions of Windows do not install a SMTP server (it is available on the installation disc).
In order to make it work on Windows you have to change the PHP configuration. Either you edit php.ini (the configuration will apply globally) or you can use function ini_set() to change it only for current execution of the current script.
The best way is to change php.ini. You can find it in the PHP's installation directory or in the Windows's directory. Check the output of PHP function phpinfo() to find out its exact location.
Open php.ini in a text editor (the one you use to write the code is the best) and search for a section that looks like this:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me#example.com
For SMTP, use the name or the IP address of your company's mail server. Or your ISP's mail server if you are at home. Or check the configuration of your email client.
The smtp_port is either 25 for standard SMTP or 587 if the server uses SSL to encrypt its communication.
Also uncomment the sendmail_from setting if it is commented out (remove the ; from the beginning of line) and put your email address there.
Read more about the PHP configuration for sending emails on Windows on the documentation page.
Another option is to install a SMTP server on the computer. You can find one on the Windows installation disc or you can use a third-party solution.
If you choose to not install a SMTP server on the computer you don't even need to modify php.ini. You can change the code of the script to use a SMTP server:
$mailer = new PHPMailer();
$mailer->IsSMTP();
$mailer->Host = "mail.example.com";
$mailer->Port = 25;
Check this PHPmailer example for all the settings and their meaning.
If the SMTP server uses SMTP authentication (the webmail providers do it, your ISP or your company might do it or might not do it) then you have to also add:
$mail->SMTPAuth = true;
$mail->Username = "yourname#example.com";
$mail->Password = "yourpassword";
If you use Gmail's SMTP server, for example, then use your Gmail email address and password. Replace "Gmail" with "Hotmail" or "Yahoo!" or your webmail provider or your company in the sentence above.
Configuring a working mail client from localhost is always a mission and often "unecessary" considering it's just a sandbox. Although some developers want to solve the puzzle (I am one of those), some look for an easier alternative.
I would suggest that you install HMailServer
I have seen lots of people having great luck at a very fast speed using hmail.
Check this post for the step by step: How to send email from localhost WAMP Server to send email Gmail Hotmail or so forth?
I would like to send email through php code hosted locally.
<?php
$email = "myemail#local.com";
$titre = "My subject";
$message = "Text message !";
mail($email, $titre, $message);
?>
When I run this code, I get the following error :
Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\...
I went into the php.ini file and it seems to be already well configured.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
How can I fix this ?
Thank you
It is configured to use localhost:25 for the mail server.
The error message says that it can't connect to localhost:25.
Therefore you have two options:
Install / Properly configure an SMTP server on localhost port 25
Change the configuration to point to some other SMTP server that you can connect to
I spent hours on this. I used to not get errors but mails were never sent. Finally I found a solution and I would like to share it.
<?php
include 'nav.php';
/*
Download PhpMailer from the following link:
https://github.com/Synchro/PHPMailer (CLick on Download zip on the right side)
Extract the PHPMailer-master folder into your xampp->htdocs folder
Make changes in the following code and its done :-)
You will receive the mail with the name Root User.
To change the name, go to class.phpmailer.php file in your PHPMailer-master folder,
And change the name here:
public $FromName = 'Root User';
*/
require("PHPMailer-master/PHPMailerAutoload.php"); //or select the proper destination for this file if your page is in some //other folder
ini_set("SMTP","ssl://smtp.gmail.com");
ini_set("smtp_port","465"); //No further need to edit your configuration files.
$mail = new PHPMailer();
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com"; // SMTP server
$mail->SMTPSecure = "ssl";
$mail->Username = "trials.php#gmail.com"; //account with which you want to send mail. Or use this account. i dont care :-P
$mail->Password = "trials.php.php"; //this account's password.
$mail->Port = "465";
$mail->isSMTP(); // telling the class to use SMTP
$rec1="trials.php#gmail.com"; //receiver. email addresses to which u want to send the mail.
$mail->AddAddress($rec1);
$mail->Subject = "Eventbook";
$mail->Body = "Hello hi, testing";
$mail->WordWrap = 200;
if(!$mail->Send()) {
echo 'Message was not sent!.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo //Fill in the document.location thing
'<script type="text/javascript">
if(confirm("Your mail has been sent"))
document.location = "/";
</script>';
}
?>
You will need to install a local mailserver in order to do this.
If you want to send it to external e-mail addresses, it might end up in unwanted e-mails or it may not arrive at all.
A good mailserver which I use (I use it on Linux, but it's also available for Windows) is Axigen:
http://www.axigen.com/mail-server/download/
You might need some experience with mailservers to install it, but once it works, you can do anything you want with it.
try this
ini_set("SMTP","aspmx.l.google.com");
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: test#gmail.com" . "\r\n";
mail("email#domain.com","test subject","test body",$headers);
It is possible to send Emails without using any heavy libraries I have included my example here.
lightweight SMTP Email sender for PHP
https://github.com/Nerdtrix/EZMAIL
Tested in both environments production and development.
and most importantly emails will not go to spam unless your IP is blacklisted by the server.
cheers.
I'm using the mail() basic example modified slightly for my user id and I'm getting the error "Mailer Error: Could not instantiate mail function"
if I use the mail function -
mail($to, $subject, $message, $headers);
it works fine, though I'm having trouble sending HTML, which is why I'm trying PHPMailer.
this is the code:
<?php
require_once('../class.phpmailer.php');
$mail = new PHPMailer(); // defaults to using php "mail()"
$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);
print ($body ); // to verify that I got the html
$mail->AddReplyTo("reply#example.com","my name");
$mail->SetFrom('from#example.com', 'my name');
$address = "to#example.com";
$mail->AddAddress($address, "her name");
$mail->Subject = "PHPMailer Test Subject via mail(), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$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!";
}
?>
Try using SMTP to send email:-
$mail->IsSMTP();
$mail->Host = "smtp.example.com";
// optional
// used only when SMTP requires authentication
$mail->SMTPAuth = true;
$mail->Username = 'smtp_username';
$mail->Password = 'smtp_password';
Your code looks good, did you forget to install PostFix on your server?
sudo apt-get install postfix
It worked for me ;)
Cheers
This worked for me
$mail->SetFrom("from#domain.co","my name", 0); //notice the third parameter
$mail->AddAddress($address, "her name");
should be changed to
$mail->AddAddress($address);
This worked for my case..
You need to make sure that your from address is a valid email account setup on that server.
If you are sending file attachments and your code works for small attachments but fails for large attachments:
If you get the error "Could not instantiate mail function" error when you try to send large emails and your PHP error log contains the message "Cannot send message: Too big" then your mail transfer agent (sendmail, postfix, exim, etc) is refusing to deliver these emails.
The solution is to configure the MTA to allow larger attachments. But this is not always possible. The alternate solution is to use SMTP. You will need access to a SMTP server (and login credentials if your SMTP server requires authentication):
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = "mail.example.com"; // set the SMTP server
$mail->Port = 26; // set the SMTP port
$mail->Username = "johndoe#example.com"; // SMTP account username
$mail->Password = "********"; // SMTP account password
PHPMailer defaults to using PHP mail() function which uses settings from php.ini which normally defaults to use sendmail (or something similar). In the above example we override the default behavior.
The PHPMailer help docs on this specific error helped to get me on the right path.
What we found is that php.ini did not have the sendmail_path defined, so I added that with sendmail_path = /usr/sbin/sendmail -t -i;
In my case, it was the attachment size limit that causes the issue. Check and increase the size limit of mail worked for me.
Seems in my case it was just SERVER REJECTION. Please check your mail server log / smtp connection accessibility.
I had this issue, and after doing some debugging, and searching I realized that the SERVER (Godaddy) can have issues.
I recommend you contact your Web hosting Provider and talk to them about Quota Restrictions on the mail function (They do this to prevent people doing spam bots or mass emailing (spam) ).
They may be able to advise you of their limits, and if you're exceeding them. You can also possibly upgrade limit by going to private server.
After talking with GoDaddy for 15 minutes the tech support was able to resolve this within 20 minutes.
This helped me out a lot, and I wanted to share it so if someone else comes across this they can try this method if all fails, or before they try anything else.
An old thread, but it may help someone like me. I resolved the issue by setting up SMTP server value to a legitimate value in PHP.ini
I had this issue as well. My solution was to disable selinux. I tried allowing 2 different http settings in selinux (something like httpd_allow_email and http_can_connect) and that didn't work, so I just disabled it completely and it started working.
I was having this issue while sending files with regional characters in their names like: VęryRęgióńął file - name.pdf.
The solution was to clear filename before attaching it to the email.
Check if sendmail is enabled, mostly if your server is provided by another company.
For what it's worth I had this issue and had to go into cPanel where I saw the error message
"Attention! Please register your email IDs used in non-smtp mails through cpanel plugin. Unregistered email IDs will not be allowed in non-smtp emails sent through scripts. Go to Mail section and find "Registered Mail IDs" plugin in paper_lantern theme."
Registering the emails in cPanel (Register Mail IDs) and waiting 10 mins got mine to work.
Hope that helps someone.
A lot of people often overlook the best/right way to call phpmailer and to put these:
require_once('../class.phpmailer.php');
or, something like this from the composer installation:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require_once "../../vendor/autoload.php";
on TOP of the page before calling or including anything else. That causes the "Could not instantiate mail function"-error by most folks.
Best solution: put all mail handling in a different file to have it as clean as possible. And always use SMTP.
If that is not working, check your DNS if your allowed to send mail.
My config: IIS + php7.4
I had the same issue as #Salman-A, where small attachments were emailed but large were causing the page to error out.
I have increased file and attachments limits in php.ini, but this has made no difference.
Then I found a configuration in IIS(6.0), and increased file limits in there.
Also here is my mail.php:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../_PHPMailer-master/src/Exception.php';
require '../_PHPMailer-master/src/PHPMailer.php';
try{
$email = new PHPMailer(true);
$email->SetFrom('internal#example.com', 'optional name');
$email->isHTML(true);
$email->Subject = 'my subject';
$email->Body = $emailContent;
$email->AddAddress( $eml_to );
$email->AddAttachment( $file_to_attach );
$email->Send();
}catch(phpmailerException $e){echo $e->errorMessage();}
future.
We nee to change the values of 'SMTP' in php.ini file
php.ini file is located into
EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion\php.ini
I have written a basic script for the mail functionality.
I am trying to run this script through WAMP server.
<?php
phpinfo();
$to = "mss#xyz.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "mohan.s#xyz.com";
$headers = "From: $from";
$res= mail($to,$subject,$message,$headers);
echo " $res Mail Sent.";
?>
I have set the SMTP, sendmail_from in the php.ini file .
It gives me the following error
Warning: mail() [function.mail]: Failed to connect to mailserver at
"mucse409.eu.xyz.com" port 25, verify your "SMTP" and "smtp_port"
setting in php.ini or use ini_set() in C:\wamp\www\email.php on line 9
Mail Sent.
I am able to ping the SMTP address from my machine. Please guide me.
Can you also send mail from this machine to this smtp server using some mail client like ms outlook or mozilla thunderbird?
I had a problem once that my provider block traffic directed at smtp ports outside due to virus infection, and I couldn't send mail because of this, but I could ping server and port.
Could be blocked by a firewall or some such.
See if you can open port 25 with telnet (If you don't have software for this, you can download putty)
Following this tutorial I was able to send mail link text.
Send email using Gmail and PHPMailer The new automatic update
generator is ready, it has been a long time since OCRALight has been
finished and little bit of this and that has been polished on the
update generation.
The process is fairly complex, it involves reverse-engineering,
data-mining, packaging, distribution and a lot o fighting with our
crappy Windows server that is between me and the final Linux
liberation.
Every step in the road has been automatized, one by one, every problem
has been solved and polished, now the final piece is in his place, the
automatic email generation. Now the updates will be made and send
everyday, even weekends and vacations.
If you are interested in the technical aspect keep reading:
How it has been done:
First of all, you need to have PHP with OpenSSL support, for Windows
you’ll need to Install PHP and carefully select OpenSSL in the
components list, if you already have PHP installed, don’t worry a
re-install will keep your configuration, and you’ll be able to select
OpenSSL.
Then download PHPMailer, and extract it near your main php
file.
You will need to have a Gmail account(obviously) I recommend you to
make a new one just for this, mainly because the configuration need to
be very precise, and you wouldn’t be able to use it freely without
loosing functionality or risking to break the configuration.
Configure your Gmail account to use POP mail, but not IMAP, ONLY POP,
just POP.
And now the code:
<?php
require(”PHPMailer/class.phpmailer.php”);
$update_emails = array(
‘Juan Perez’ => ‘Juan_Perez#jalisco.gob.mx’,
‘Francisco Garcia’ => ‘fgarcia#hotmail.com’,
‘Diana la del Tunel’ => ‘diana#gmail.com’
);
echo “\nSending Update Email\n”;
$mail = new PHPMailer(); // Instantiate your new class
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host = “smtp.gmail.com”; // specify main and backup server
$mail->SMTPSecure= ’ssl’; // Used instead of TLS when only POP mail is selected
$mail->Port = 465; // Used instead of 587 when only POP mail is selected
$mail->Username = “youremail#gmail.com”; // SMTP username, you could use your google apps address too.
$mail->Password = “yaourextremelynotlamepassword”; // SMTP password
$mail->From = “youremail#gmail.com”; //Aparently must be the same as the UserName
$mail->FromName = “Your name”;
$mail->Subject = ‘The subject’;
$mail->Body = “The body of your message”;
foreach ($update_emails as $name => $email) {
$mail->AddBcc($email, $name);
}
if(!$mail->Send())
{
echo “There was an error sending the message:” . $mail->ErrorInfo;
exit;
}
echo “Done…\n”;
?>
In this code I send the email to a group of people, thus I use the
“Bcc:” field instead of the “To:” one, to add a “To:” you would use
AddAddress($email, $name).
A possible upgrade would be to use a MySQL database to store the
addresses, and provide a web interface to add and remove
them. for the moment, this is enough.
Soo remember:
PHP with OpenSSL; PHPMailer; Create a Gmail Account; Activate POP Host:
smtp.gmail.com; SMTPAuth=true; SMTPSEcure=ssl; Port: 465; User with Domain;
Password; $Mail->send();