问题
I am trying to send mail from localhost. but i am unable to send the mail from localhost so can anybody tell me that how to reconfigure my xampp to send mail from localhost
回答1:
You can send mail from localhost with sendmail package , sendmail package is inbuild in XAMPP. So if you are using XAMPP then you can easily send mail from localhost.
for example you can configure C:\xampp\php\php.ini
and c:\xampp\sendmail\sendmail.ini
for gmail to send mail.
in C:\xampp\php\php.ini
find extension=php_openssl.dll
and remove the semicolon from the beginning of that line to make SSL working for gmail for localhost.
in php.ini file find [mail function]
and change
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = my-gmail-id@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
Now Open C:\xampp\sendmail\sendmail.ini
. Replace all the existing code in sendmail.ini with following code
[sendmail]
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
Now you have done!! create php file with mail function and send mail from localhost.
PS: don't forgot to replace my-gmail-id and my-gmail-password in above code.
Also, don't forget to remove duplicate keys if you copied settings from above. For example comment following line if there is another sendmail_path : sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe"
in the php.ini file
Also remember to restart the server using the XAMMP control panel so the changes take effect.
For gmail please check https://support.google.com/accounts/answer/6010255 to allow access from less secure apps.
To send email on Linux (with sendmail package) through Gmail from localhost please check PHP+Ubuntu Send email using gmail form localhost.
回答2:
In XAMPP v3.2.1 for testing purposes you can see the emails that the XAMPP sends in XAMPP/mailoutput. In my case on Windows 8 this did not require any additional configuration and was a simple solution to testing email
回答3:
Its very simple to send emails on localhost or local server
Note: I am using the test mail server software on Windows 7 64bit with Xampp installed
Just download test mail server tool and install according to the instruction given on its website Test Mail Server Tool
Now you need to change only two lines under php.ini
file
- Find
[mail function]
and remove semi colon which is before;smtp = localhost
- Put the semi colon before
sendmail_path = "C:\xampp\mailtodisk\mailtodisk.exe"
You don't need to change anything else, but if you still not getting emails than check for the SMTP port
, the port number must be same.
The above method is for default settings provided by the Xampp software.
回答4:
You have to configure SMTP on your server. You can use G Suite SMTP by Google for free:
<?php
$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 = "your-gmail-account@gmail.com"; // GMAIL username
$mail->Password = "your-gmail-password"; // GMAIL password
}
// Typical mail data
$mail->AddAddress($email, $name);
$mail->SetFrom($email_from, $name_from);
$mail->Subject = "My Subject";
$mail->Body = "Mail contents";
try{
$mail->Send();
echo "Success!";
} catch(Exception $e){
// Something went bad
echo "Fail :(";
}
?>
Read more about PHPMailer
here.
回答5:
You can test send mail in Your PC without Internet
you should use Papercut this simple application to test send mail. and you don't need to configure anything.
Just run it and try test send mail:
test_sendmail.php
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
and you will see this:
I hope you will have a good day. you can find me on Youtube for more tutorial Piseth Sok
Cheer!
回答6:
For people on windows 8 if you want to do this i would really recommend reading this tutorial i found: http://yogeshchaugule.com/blog/2013/configure-sendmail-wamp
Its not written by me but after slamming my head into a concrete wall for 2,5 hours not getting this to work with the weirdest errors like:
- Connection timed out.
- Connection Closed Gracefully.
I finally found that tutorial were upon installation of https://www.stunnel.org/downloads.html and the configuration of Stunnel. It finally worked.
回答7:
If you have an installed copy of xampp latest copy then check this link for complete documentation of sending emails through xampp. You must enable apache before you try to access the below link
http://localhost/dashboard/docs/send-mail.html
回答8:
As in my personal experience I found that very similar thing to Vikas Dwivedi answer will work just fine.
Step 1 (php.ini file)
In php.ini file located in xampp\php\php.ini
. Change settings to the following:
extension=php_openssl.dll
[mail function]
sendmail_path =":\xampp7\sendmail\sendmail.exe -t"
mail.add_x_header=On
Turn off other variables under mail funciton
by putting ;
before them. e.g ;smtp_port=25
Step 2 (sendmail.ini file)
In sendmail.ini located in xampp\sendmail\semdmail.ini change to the following:
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=auto
auth_username=address@gmail.com
auth_password=YourPassword
Step 3 (code)
Create a php file and use the following:
<?php
mail($to, "subject", "body", "From: ".$from);
?>
Notice
- You need to restart apache in order for php.ini to reload.
- you need to activate Google Less secure app access in https://myaccount.google.com/u/1/security
- It might help to run Xampp with Admin permission.
回答9:
This code is used for the mail from your localhost XAMPP and your Gmail account. This code is very easy and working for me try your self.
Below Change In php.ini File
SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = your@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
extension=php_openssl.dll
Below Change In sendmail.ini File
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
auth_username=yourmail@gmail.com
auth_password=your-gmail-password
force_sender=yourmail@gmail.com
Please write the belove code in your PHP file to send email
<?php
$to = "tomail@gmail.com";
$subject = "Test Mail";
$headers = "From: from_mail@gmail.com\r\n";
$headers .= "Reply-To: replytomail@gmail.com\r\n";
$headers .= "CC: theassassin.edu@gmail.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img src="//css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>Details</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>Details</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>Details</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>Details</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>Details</td></tr>";
$addURLS = 'google.com';
if (($addURLS) != '') {
$message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . $addURLS . "</td></tr>";
}
$curText = 'dummy text';
if (($curText) != '') {
$message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>New Text</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
if(mail($to,$subject,$message,$headers))
{
echo "Mail Send Sucuceed";
}
else{
echo "Mail Send Failed";
}
?>
回答10:
You have to define an SMTP
server and a port for this. All except like sending mails from live hosts.
This is a useful link regarding this.
NB: The port should be unused. Please take care that, Some applications like
Skype
uses the default ports and there by prevents sending mail.
回答11:
just spent over an hour trying to make this work. for everybody having the same trouble with all the suggestions posted not working: you have to restart Apache in your XAMPP inrerface! just restarting XAMPP wont work!!
来源:https://stackoverflow.com/questions/15965376/how-to-configure-xampp-to-send-mail-from-localhost