从本地主机XAMPP发送电子邮件 [英] Send Email from Localhost XAMPP
问题描述
我可以知道如何从localhost发送电子邮件到Gmail或其他电子邮件帐户?我已经就这个事情进行了研究,试图做到这一点,但仍然不能发送电子邮件。以下是我编辑的 sendmail.ini
和 php.ini
文件,
May I know how to send an email from localhost to gmail or other email accounts? I already make research regarding this matter and tried to do it but still can not send the email. Below are my sendmail.ini
and php.ini
files that I edit,
sendmail.ini
smtp_server=smtp.gmail.com
smtp_port=465
smtp_ssl=ssl
error_logfile=error.log
debug_logfile=debug.log
auth_username=khairulamran.nazri@gmail.com
auth_password=[email password]
pop3_server=
pop3_username=
pop3_password=
force_sender=khairulamran.nazri@gmail.com
force_recipient=
hostname=smtp.gmail.com
php.ini - 邮件功能
SMTP = smtp.gmail.com
smtp_port = 465
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
mail.add_x_header=Off
contact.php - 发送电子邮件
contact.php - to send the email
<?php
if(isset($_POST['submitted'])){
$name=$_POST['name'];
$to=$_POST['email'];
$hp=$_POST['hp'];
$subject="Test";
$msg="Thank you for Register. Your Name is ".$name." and Hp no. is ".$hp;
$header="khairulamran.nazri@gmail.com";
$success=mail($to,$subject,$msg,$header);
if($success==true){
echo "Email send successfully ";
} else{
echo "Error sending email";
}
}
?>
<form name="contact" method="post" action="">
Nama:<input type="text" name="name"><p>
Email:<input type="text" name="email"><p>
Hp:<input type="text" name="hp">
<input type="submit" name="submitted" value="Submit">
</form>
如果点击提交,它将不会发送已提交的电子邮件。
If click Submit, it will not send the email that have been submitted.
推荐答案
尝试使用邮件库。我已经习惯了,它会很好的工作。
跟着这个 https://github.com/PHPMailer/PHPMailer
Try to use mailer library. I had used and it will work perfectly. Follow this. https://github.com/PHPMailer/PHPMailer
您只需输入您的gmail凭据,之后就可以使用。
You would need to only enter your gmail credentials and after that it will work.
这篇关于从本地主机XAMPP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!