Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中使用发送确认电子邮件_Php_Mysql_Email - Fatal编程技术网

在php中使用发送确认电子邮件

在php中使用发送确认电子邮件,php,mysql,email,Php,Mysql,Email,我有一个php代码发送确认电子邮件。但是如何使用我的邮件服务器将此电子邮件发送给注册用户。使用gmail发送confirmarion电子邮件的示例 <?php if(isset($_SESSION['error'])) { header("Location: index.php"); exit; } else { $username = $_POST['username'];

我有一个php代码发送确认电子邮件。但是如何使用我的邮件服务器将此电子邮件发送给注册用户。使用gmail发送confirmarion电子邮件的示例

<?php   
    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 from  MyName to $username"; 
            $header = "TutsforWeb: Confirmation from TutsforWeb"; 
            $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 Email Address."; 
        } else { 
          echo "Cannot send Confirmation link to your e-mail address"; 
        } 
     } 
  } 
 } 
?>

如果您拥有邮件服务器凭据,则可以使用SMTP发送电子邮件。你也可以使用它,这是非常容易使用的

第一件事是您需要从上面的链接安装PHPMailer,然后使用以下代码 `
如果您有邮件服务器,则遵循邮件服务器规则


您可以使用PHPMailer并遵循PHPMailer函数的规则

修复:您必须查明是否已在服务器实例中安装了邮件服务器。这取决于服务器环境。您可以找到如何使用简单的web搜索。 提示:如果只是正常地从操作中获得响应,则邮件服务器未连接。但如果它一直等待4到5秒,这意味着大部分时间服务器都有问题。 Ubuntu-[如何安装后缀][1] Windows-[SMTP电子邮件][2]

其他问题: 一旦您可以使用php邮件功能发送邮件,但仍然必须提供准确的标题信息,否则邮件将发送到垃圾邮件文件夹

错误:$header=“TutsforWeb:来自TutsforWeb的确认”; 正确:
$headers='来自:webmaster@example.com' . “\r\n”。
答复:webmaster@example.com' . “\r\n”。
“X-Mailer:PHP/”。phpversion()


如果您想使用gmail,只需参考以下内容:

您首先从存储注册用户的表中获取数据,然后就可以向注册用户发送邮件

Download PHPMailerAutoload 



首先格式化您的问题,使其更易于阅读。您可以使用php mailer使用samle gmail id和pass编辑上述代码。非常感谢你,因为那部分把我弄糊涂了。请使用gmail使用示例邮件服务器设置编辑我的代码。谢谢,先生。它可以在本地主机上工作(在我的桌面xampp服务器中?)
Download PHPMailerAutoload 
<?php

// When we unzipped PHPMailer, it unzipped to
// public_html/PHPMailer_5.2.0

require("lib/PHPMailer/PHPMailerAutoload.php");
$mail = new PHPMailer();

// set mailer to use SMTP
$mail->IsSMTP();

// we are setting the HOST to localhost
$mail->Host = "mail.example.com";  // specify main and backup server
$mail->SMTPAuth = true;     // turn on SMTP authentication

// When sending email using PHPMailer, you need to send from a valid email address
// In this case, we setup a test email account with the following credentials:
$mail->Username = "user@gmail.com";  // SMTP username
$mail->Password = "password"; // SMTP password

$mail->From = "from@example.com";

// below we want to set the email address we will be sending our email to.
$mail->AddAddress("to@example.com", "To whom");

// set word wrap to 50 characters
$mail->WordWrap = 50;
// set email format to HTML
$mail->IsHTML(true);

$mail->Subject = "You have received feedback from your website!";
$message = "Text Message";
$mail->Body    = $message;
$mail->AltBody = $message;

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
?>