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?
Related
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.
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.
Situation:
I run a PHP script from a windows 7 machine using CLI.
My script will do its thing and then generate 1 log file at the end.
I already got all that part working.
In addition to that, I want to email myself that log file every time the script runs.
Somewhere in the bottom of my script I tried this :
mail('email#gmail.com', 'Report', strip_tags($response). PHP_EOL );
The script run all the way to the bottom, I got my log file to generate, I also got a report on my CLI as well, but I never receive any email.
Result :
I am not sure is because I :
am on a Windows.
need to allow specific php extension
Need to configure more setting in my php.ini.
Can someone help clarify this issue ?
You need a Mail Server which is configured in the PHP.ini to send your mails.
Here is a short Tutorial:
http://geekswithblogs.net/tkokke/archive/2009/05/31/sending-email-from-php-on-windows-using-iis.aspx
Note that the IIS6 console still needed for the Mail Server, also if you're hosting on >=IIS7.
Also you need to make sure, your Mail Server is acceptet by the Mail Server you want to send this mail to. This is definitve not a trival task. Gmail and GMX for example never accept it, if you didn't have Reverse DNS correctly configured.
If you don't know how, I highly recommend to have a talk to your System Administrator. Mail Server are very hard to setup correctly. It's a task I work around.
But here are the good news, if you do not want to configure your own mail server. It is very simple with an Hosted Email Adress and SMTP, if your using the Open Source Project PHPMailer:
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'user#example.com'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//More in the Documentation
It has a powerfull SMTP Class, which helps extreme for login into any SMTP Account (Gmail for example).
I am new to PHP and just started learning it. I am trying to send a test mail to my gmail account using the mail() function.
Here is my code:
$message = "Hello PHP!";
mail("mygmailaccount#gmail.com", "PHP Test", $message);
But its not working. This is what the error looks like:
Click here to view it in a webpage.
I have seen lots of similar questions and I have also tried all the solutions mentioned on SO.
I have made changes to my php.ini file as shown below.
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = mygmailaccount#gmail.com
I am using WAMP server on a Windows 7 (64-bit) machine.
Please help me solve this. Thanks!
https://github.com/PHPMailer/PHPMailer
This is the official PHPMailer.
all you have to do is upload all the files and folders to a folder with the mailing php file(the file which have the code shown by you). Then look at the example folder or look at the example folders if you need smtp.You should have figured it out , looks like you got good programming skill.If you have problem , comment to informed me.
PS. mail() function sometimes not reliable. I face that problem often until I use phpmailer for my own system.
EDIT: Put it altogether like this. send.php is the file I'm going to write the followling code.
Next , the send.php code!!
<?php
require 'PHPMailerAutoload.php';
$sendto ="destinationemail";//Input your own
$sendfrom ="yourmaskedmail";//input your own
$topic ="test";
$passage ="test";
$mail = new PHPMailer(true);
//Send mail using gmail
if($send_using_gmail){
$mail->IsSMTP(); // telling the class to use SMTP
$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 = "*hidden*"; // GMAIL username Input your own
$mail->Password = "*hidden"; // GMAIL password Input your own
}
//Typical mail data
$mail->AddAddress($sendto,$sendto);
$mail->SetFrom($sendfrom,$sendfrom);
$mail->Subject =$topic;
$mail->Body =$passage;
try{
$mail->Send();
echo "Success! This email has been sent to ".$sendto. " in the name of ".$sendfrom;
} catch(Exception $e){
//Something went bad
echo "Unable to process your request now, please try again later";
}
?>
Change the mailsender,mailreciever and contents of the mail. Also , input your gmail username and password. After that, run the php, wait for your email to come. I've just test it 8 minutes ago and it worked.
Have a look at this page:
http://www.php.net/manual/en/mail.configuration.php
Short version: to make your php.mail function work, you need to figure out how to send an e-mail using your server and make sure your configuration in php.ini is up to date. (For details, see the link above).
Does your server run sendmail or another mail agent? Or doesn't it run anything like that at all?
If so, make sure the paths are set correctly.
If not, use a third party SMTP service. GMail offers it, but the problem is that it requires authentication, which php.mail() doesn't support. If you still want to use it, see this post for alternatives to php.mail().
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();