如何配置xampp发送电子邮件

2023-11-24

我知道这是网站上的其他地方,但由于某种原因,我在这里找到的答案仍然没有帮助,在尝试了一整天不同的事情后,我仍然无法让它工作。我的目标是将确认码发送到用户输入的电子邮件中。我只了解少量的 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.com 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.com

; 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.com

; 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= [email protected]
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

[email protected]

; 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.com
smtp_port =587

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = [email protected]


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 .= "http://www.yourname.com/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";
   }
  }
 }
}
?>

就像我说的,我已经研究这个问题有一段时间了,但我似乎无法弄清楚,我认为这非常简单,但由于我仍在学习,所以我没有看到它。感谢您的帮助!


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

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

SMTP=smtp.gmail.com
smtp_port=587
sendmail_from = [email protected]
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"

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

[sendmail]
    
smtp_server=smtp.gmail.com
smtp_port=587
error_logfile=error.log
debug_logfile=debug.log
[email protected]
auth_password=your-gmail-id-password
[email protected]

现在你已经完成了!创建一个具有邮件功能的 PHP 文件并从本地主机发送邮件。

注意:- 将您的电子邮件 ID 替换为“[电子邮件受保护]"

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何配置xampp发送电子邮件 的相关文章

  • 使用 Ajax 和 PHP 上传图像

    我想将图像上传到我的服务器 并控制 HTML 代码中的 PHP 回显 为此 我想使用 jQuery Ajax 但我不知道如何使用 Ajax 将图像发送到 PHP 这是一个大学项目 所以我不能使用任何类型的插件 我的实际代码 HTML
  • 以零开头的字符串/数字的正确格式?

    我正在尝试使用 PHP 创建一个包含电话号码列表的文件 它工作正常 但如果电话号码以零开头 则该数字将从 Excel 文件中删除 有谁知道如何正确设置格式以使其保持不变 Either Set the value explicitly as
  • 我是否需要破解 ZendFramework1.10.8/Doctrine1.2.2 才能生成模型?

    我已经开始阅读 zend 框架 它与 Doctrine 一起使用 并实现了一个小项目来掌握理解 我已经到了需要生成模型的地步 就像拥有一个生成脚本一样 如 Doctrine 1 2 中建议的那样 2 pdf 手册 经过几次不成功的尝试 例如
  • Yii 添加条件

    我尝试根据我的条件从表中获取行 我的代码 conditions array id gt array 148028 118508 criteria new CDbCriteria foreach conditions as key gt va
  • 执行 mysqli->set_charset() 的永久方法?

    将我可以找到的字符集的所有配置文件和运行时选项设置为 utf 8 后 使用 php 建立的新 mysqli 连接的字符集仍然设置为 latin1 这实际上意味着我必须调用 mysqli gt set charset utf8 每次我连接 m
  • PHP,检查 URL 和文件是否存在?

    我为 WordPress 创建了一个插件 需要存在两个文件才能正常运行 第一个文件定义为文件系统路径 第二个文件定义为 URL 假设第一个文件是 home my site public html some folder required f
  • php 测试字符串是否包含三个字符串之一?

    实现以下目标的最佳方法是什么 我有一个 img变量包含例如myimage left jgp someimage center jpg or img right jpg 最好的测试方法是什么 left right or center文件名并提
  • 将 PHP 错误存储在日志文件中

    我想将 php 生成的任何错误和警告存储在日志文件中 但是still也以正常方式显示它们 回显 Thanks 您可以定义自己的函数并描述如何处理错误 http www php net manual en function set error
  • Laravel - 如何使用供应商类?

    我想在 m paths php 文件上使用移动检测 我已将该包添加为composer json 中的必需项 并将其安装在供应商文件中 我现在该如何使用它 我尝试了这个答案 但没有成功 因为找不到该课程 Laravel 4 使用供应商类 ht
  • 关联数组与 SplObjectStorage

    我正在编写代码来管理一组独特的对象 该代码的第一个原型使用关联数组 基本上就像我一直这样做的方式一样 然而 我也热衷于利用 PHP 的更现代版本中添加的功能 例如 SplObjectStorage 1 这样做 部分是作为一种学习经验 部分是
  • 使用类型映射选项的 PHP SoapClient 示例

    我在 PHP 的 SoapClient 中的命名空间使用方面遇到了一个小问题 从文档中我相信构造函数的类型映射选项将解决我的问题 http php net manual en soapclient soapclient php http p
  • 在订单编辑页面添加自定义元框并将其显示在客户订单页面上

    在 WooCommerce 中 想要在 WooCommerce 管理订单页面上添加自定义元框 在此框中 我只想在保存到该订单的文本字段中输入跟踪号码 然后在客户查看订单页面上 我想显示一个按钮 用于打开带有跟踪信息的模式 该模式只会拉入一个
  • PHP file_get_contents() 和设置请求标头

    使用 PHP 是否可以发送 HTTP 标头file get contents 我知道您可以从您的php ini文件 但是 您是否还可以发送其他信息 例如HTTP ACCEPT HTTP ACCEPT LANGUAGE and HTTP CO
  • 原始 POST 数据是什么?

    我试图理解原始 POST 数据的含义 PHP 手册页 HTTP RAW POST DATA http php net manual en reserved variables httprawpostdata php只是声明这个变量包含Raw
  • 设置基于 PHP 定时器的函数

    我有一个 php 文件test php 我想要echo or print5 秒后 即在浏览器调用 加载或打开 php 文件后不久 成功 顺便说一句 有时我可能想在特定的时间间隔后执行 初始化某些函数 如何使用 php 执行面向时间的任务 例
  • 来自外部文件的 PHP 变量?

    编辑 完成的解决方案 工作代码 所以 这是我的一个朋友帮我想出来的 这是我在 K2 items php 文件中使用的部分 div class fb comments div
  • (mysql, php) 如何在插入数据之前获取auto_increment字段值?

    我正在将图像文件上传到存储服务器 在上传之前 我应该编写文件名 其中包含自动增量值 例如 12345 filename jpg 在插入数据库之前如何获取自动增量值 我只看到一种解决方案 插入空行 获取其自增值 删除这一行 使用 p 1 中的
  • 从php字符串中删除奇怪的字符

    这就是我现在所拥有的 将 RSS feed 绘制到 php 中 RSS feed 中的原始 xml 如下所示 Paul 8217 s Confidence 到目前为止我拥有的 php 是这样的 newtitle item gt title
  • 一个模型中的多个表 - Laravel

    我的索引页使用数据库中的 3 个表 索引滑块 索引特征 页脚框 我使用一个控制器 IndexController php 并像这样调用三个模型 public function index return View make index gt
  • 为什么 foreach 这么慢?

    PHPBench com http www phpbench com 在每个页面加载上运行快速基准测试脚本 在 foreach 测试中 当我加载它时 foreach 的运行时间是第三个示例的 4 到 10 倍 为什么本机语言构造明显比执行逻

随机推荐