【问题标题】:Wamp Server and PHP mailerWamp 服务器和 PHP 邮件程序
【发布时间】:2016-02-27 05:57:05
【问题描述】:

我有一个 WAMP 服务器数据库,其中包含用户及其电子邮件和激活码。 如何自动为 WAMP 服务器数据库中的每条新记录及其激活码发送电子邮件?使用 PHP。 P.s:我已经可以使用 PHP 邮件程序从 WAMP 发送电子邮件,但我每次都必须指定收件人。

这是我使用 PHP 邮件程序发送电子邮件的 mail.php 脚本

<?php
   require "init.php";
   require"PHPMailerAutoload.php";
   require 'class.phpmailer.php';

   $mail = new PHPMailer();
   $mail->IsSMTP();
   $mail->SMTPAuth = true;
   $mail->SMTPSecure = 'tls';   
   $mail->Mailer = "smtp";
   $mail->Host = "smtp.gmail.com";
   $mail->Port = "587"; 
   $mail->IsHTML(true);
   $mail->Username = "******@gmail.com";
   $mail->Password = "******";

   $mail->From     = "*******@gmail.com";
   $mail->FromName = "Vodafone-El7a2ny";
   $mail->AddAddress("*****", "Marwa Hashem");

   $mail->Subject  = "Activation Code";
   $mail->Body     = " Dear User,


                    Thank you for registering in El72any Mobile Application,

                  Your Activation Code is 


Best Regards,
****";

   $mail->WordWrap = 50;  

   if(!$mail->Send()) {
        echo 'Email was not sent.';
        echo 'Mailer error: ' . $mail->ErrorInfo;
        exit;
   } else {
        echo 'Email has been sent.';
   }
?>

这是 register.php 脚本

<?php
require "init.php";
$EmailAddress=$_POST["EmailAddress"];
$MobileNumber=$_POST["MobileNumber"];
$Password=$_POST["Password"];

$sql_query = "insert into user_information VALUES('$EmailAddress', '$MobileNumber', '$Password','');";



if(mysqli_query($con,$sql_query))
{
echo "<h3>Database Insertion Success...</h3>";
}

else
{
echo "Data Inerstion Error...".mysqli_error($con);
}
?>

这也是我用来连接数据库的 init.php 脚本

<?php
$db_name="CustomerDB";
$mysql_user="root";
$mysql_pass=null;
$server_name="localhost";


$con=mysqli_connect($server_name,$mysql_user,$mysql_pass,$db_name);

if(!$con)
{
echo "Connection Error...".mysqli_connect_error();


}

else
{
echo "<h3>Database connection Success...</h3>";

}



?>

【问题讨论】:

    标签: phpmailer wampserver


    【解决方案1】:

    这确实是一个意见问题,因为您没有发布任何代码。从阅读 PHPMailer 提供的文档和示例开始会有所帮助。在您的情况下,请从 the mailing list example 开始。

    【讨论】:

    • 我添加了注册代码和邮件php脚本我想要的是,每当用户注册后将新记录插入数据库时​​,都会自动向该用户发送一封确认邮件正文包含用户的激活码(这是表中的主键,在 WAMP 服务器数据库中自动递增),那么我该如何检索两者?
    • 非常感谢邮件列表示例对我帮助很大!
    猜你喜欢
    • 2013-05-28
    • 1970-01-01
    • 2012-02-22
    • 2013-07-16
    • 2018-07-07
    • 2013-11-21
    • 1970-01-01
    • 2013-10-28
    • 1970-01-01
    相关资源
    最近更新 更多