如何配置Xampp发送电子邮件

编程入门 行业动态 更新时间:2024-10-15 10:21:17
本文介绍了如何配置Xampp发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我知道它在网站上的其他地方,但是由于某些原因,我在这里找到的答案仍然没有帮助,我整日尝试不同的方法后仍然无法使它正常工作.我的目标是将确认代码发送到用户输入的电子邮件中.我只知道少量的PHP,并且遵循了有关登录/注册系统的教程,但是我相当确定php可以正常工作,并且问题出在我的sendmail.ini和php.ini中.这是我的sendmail.ini

; configuration for fake sendmail ; if this file doesn't exist, sendmail.exe will look for the settings in ; the registry, under HKLM\Software\Sendmail [sendmail] ; you must change mail.mydomain to your smtp server, ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup) ; emails delivered via IIS's pickup directory cause sendmail to ; run quicker, but you won't get error messages back to the calling ; application. smtp_server=smtp.gmail ; smtp port (normally 25) smtp_port=587 ; SMTPS (SSL) support ; auto = use SSL for port 465, otherwise try to use TLS ; ssl = alway use SSL ; tls = always use TLS ; none = never try to use SSL smtp_ssl=auto ; the default domain for this server will be read from the registry ; this will be appended to email addresses when one isn't provided ; if you want to override the value in the registry, uncomment and modify ;default_domain=mydomain ; log smtp errors to error.log (defaults to same directory as sendmail.exe) ; uncomment to enable logging error_logfile=error.log ; create debug log as debug.log (defaults to same directory as sendmail.exe) ; uncomment to enable debugging debug_logfile=debug.log ; if your smtp server requires authentication, modify the following two lines auth_username= myemail@gmail auth_password= mygmailpass ; if your smtp server uses pop3 before smtp authentication, modify the ; following three lines. do not enable unless it is required. pop3_server= pop3_username= pop3_password= ; force the sender to always be the following email address ; this will only affect the "MAIL FROM" command, it won't modify ; the "From: " header of the message content force_sender=myemail@gmail ; force the sender to always be the following email address ; this will only affect the "RCTP TO" command, it won't modify ; the "To: " header of the message content force_recipient= ; sendmail will use your hostname and your default_domain in the ehlo/helo ; smtp greeting. you can manually set the ehlo/helo name if required hostname=

还有我在php.ini中编辑的部分

extension=php_openssl.dll [mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP =smtp.gmail smtp_port =587 ; For Win32 only. ; php/sendmail-from sendmail_from = myemail@gmail sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" ;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters =

和我的PHP代码,以备不时之需

<?php session_start(); include('configdb.php'); if(isset($_POST['submit'])) { //whether the username is blank if($_POST['username'] == '') { $_SESSION['error']['username'] = "User Name is required."; } //whether the email is blank if($_POST['email'] == '') { $_SESSION['error']['email'] = "E-mail is required."; } else { //whether the email format is correct if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email'])) { //if it has the correct format whether the email has already exist $email= $_POST['email']; $sql1 = "SELECT * FROM user WHERE email = '$email'"; $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error()); if (mysqli_num_rows($result1) > 0) { $_SESSION['error']['email'] = "This Email is already used."; } } else { //this error will set if the email format is not correct $_SESSION['error']['email'] = "Your email is not valid."; } } //whether the password is blank if($_POST['password'] == '') { $_SESSION['error']['password'] = "Password is required."; } //if the error exist, we will go to registration form if(isset($_SESSION['error'])) { header("Location: index.php"); exit; } else { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $com_code = md5(uniqid(rand())); $sql2 = "INSERT INTO user (username, email, password, com_code) VALUES ('$username', '$email', '$password', '$com_code')"; $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error()); if($result2) { $to = $email; $subject = "Confirmation for $username"; $header = "Confirmation from"; $message = "Please click the link below to verify and activate your account. rn"; $message .= "www.yourname/confirm.php?passkey=$com_code"; $sentmail = mail($to,$subject,$message,$header); if($sentmail) { echo "Your confirmation link has been sent to your e-mail address."; } else { echo "Error while sending confirmation link to your e-mail address"; } } } } ?>

就像我说的那样,我已经花了一段时间了,但我似乎无法弄清楚,我认为这确实很简单,但是由于我仍在学习,所以我没有看到它.感谢您的所有帮助!

解决方案

您只需为Gmail发送邮件配置C:\ xampp \ php \ php.ini和c:\ xampp \ sendmail \ sendmail.ini.

在php.ini文件中找到[邮件功能]并更改以下内容

SMTP=smtp.gmail smtp_port=587 sendmail_from = your-gmail-id@gmail sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

现在打开C:\ xampp \ sendmail \ sendmail.ini.用以下代码替换sendmail.ini中所有现有的代码

[sendmail] smtp_server=smtp.gmail smtp_port=587 error_logfile=error.log debug_logfile=debug.log auth_username=your-gmail-id@gmail auth_password=your-gmail-id-password force_sender=your-gmail-id@gmail

现在您已经完成了!使用mail函数创建一个PHP文件,并从本地主机发送邮件.

注意:-将电子邮件ID替换为"your-gmail-id@gmail"

I know this is elsewhere on the site but for some reason the answers I've found on here still haven't helped I still can't get it to work after trying different things all day. My goal was to have a confirmation code sent to the email that the user enters. I only know a small amount of PHP and followed a tutorial for the login/registration system but I'm fairly sure the php is working fine and the problem lies in my sendmail.ini and php.ini. Here is my sendmail.ini

; configuration for fake sendmail ; if this file doesn't exist, sendmail.exe will look for the settings in ; the registry, under HKLM\Software\Sendmail [sendmail] ; you must change mail.mydomain to your smtp server, ; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup) ; emails delivered via IIS's pickup directory cause sendmail to ; run quicker, but you won't get error messages back to the calling ; application. smtp_server=smtp.gmail ; smtp port (normally 25) smtp_port=587 ; SMTPS (SSL) support ; auto = use SSL for port 465, otherwise try to use TLS ; ssl = alway use SSL ; tls = always use TLS ; none = never try to use SSL smtp_ssl=auto ; the default domain for this server will be read from the registry ; this will be appended to email addresses when one isn't provided ; if you want to override the value in the registry, uncomment and modify ;default_domain=mydomain ; log smtp errors to error.log (defaults to same directory as sendmail.exe) ; uncomment to enable logging error_logfile=error.log ; create debug log as debug.log (defaults to same directory as sendmail.exe) ; uncomment to enable debugging debug_logfile=debug.log ; if your smtp server requires authentication, modify the following two lines auth_username= myemail@gmail auth_password= mygmailpass ; if your smtp server uses pop3 before smtp authentication, modify the ; following three lines. do not enable unless it is required. pop3_server= pop3_username= pop3_password= ; force the sender to always be the following email address ; this will only affect the "MAIL FROM" command, it won't modify ; the "From: " header of the message content force_sender=myemail@gmail ; force the sender to always be the following email address ; this will only affect the "RCTP TO" command, it won't modify ; the "To: " header of the message content force_recipient= ; sendmail will use your hostname and your default_domain in the ehlo/helo ; smtp greeting. you can manually set the ehlo/helo name if required hostname=

And my the parts I've edited in my php.ini

extension=php_openssl.dll [mail function] ; XAMPP: Comment out this if you want to work with an SMTP Server like Mercury SMTP =smtp.gmail smtp_port =587 ; For Win32 only. ; php/sendmail-from sendmail_from = myemail@gmail sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" ;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" ; Force the addition of the specified parameters to be passed as extra parameters ; to the sendmail binary. These parameters will always replace the value of ; the 5th parameter to mail(), even in safe mode. ;mail.force_extra_parameters =

and my PHP code in case it's needed

<?php session_start(); include('configdb.php'); if(isset($_POST['submit'])) { //whether the username is blank if($_POST['username'] == '') { $_SESSION['error']['username'] = "User Name is required."; } //whether the email is blank if($_POST['email'] == '') { $_SESSION['error']['email'] = "E-mail is required."; } else { //whether the email format is correct if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email'])) { //if it has the correct format whether the email has already exist $email= $_POST['email']; $sql1 = "SELECT * FROM user WHERE email = '$email'"; $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error()); if (mysqli_num_rows($result1) > 0) { $_SESSION['error']['email'] = "This Email is already used."; } } else { //this error will set if the email format is not correct $_SESSION['error']['email'] = "Your email is not valid."; } } //whether the password is blank if($_POST['password'] == '') { $_SESSION['error']['password'] = "Password is required."; } //if the error exist, we will go to registration form if(isset($_SESSION['error'])) { header("Location: index.php"); exit; } else { $username = $_POST['username']; $email = $_POST['email']; $password = $_POST['password']; $com_code = md5(uniqid(rand())); $sql2 = "INSERT INTO user (username, email, password, com_code) VALUES ('$username', '$email', '$password', '$com_code')"; $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error()); if($result2) { $to = $email; $subject = "Confirmation for $username"; $header = "Confirmation from"; $message = "Please click the link below to verify and activate your account. rn"; $message .= "www.yourname/confirm.php?passkey=$com_code"; $sentmail = mail($to,$subject,$message,$header); if($sentmail) { echo "Your confirmation link has been sent to your e-mail address."; } else { echo "Error while sending confirmation link to your e-mail address"; } } } } ?>

Like I said I've been working on this for a while and I can't seem to figure it out, I assume it's something really simple but since I'm still learning I didn't see it. Thanks for all the help!

解决方案

You can just configure C:\xampp\php\php.ini and c:\xampp\sendmail\sendmail.ini for Gmail to send mail.

In php.ini file find [mail function] and change following

SMTP=smtp.gmail smtp_port=587 sendmail_from = your-gmail-id@gmail 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 smtp_port=587 error_logfile=error.log debug_logfile=debug.log auth_username=your-gmail-id@gmail auth_password=your-gmail-id-password force_sender=your-gmail-id@gmail

Now you have done!! create a PHP file with mail function and send mail from the localhost.

Note:- Replace your email id with "your-gmail-id@gmail"

更多推荐

如何配置Xampp发送电子邮件

本文发布于:2023-11-24 00:12:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送电子邮件   Xampp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!