如何在我的应用程序中从gmail发送电子邮件?

时间:2013-09-04 14:02:14

标签: php

我有以下代码。我想在用户点击“注册”按钮后立即向用户发送确认电子邮件。当我点击注册按钮时,我的数据库会使用正确的信息进行更新,但它不会发送电子邮件。

Email.php:

<?php
include('class.phpmailer.php');
include('class.smtp.php');
$mail  = new PHPMailer();   
$mail->IsSMTP();

//GMAIL config
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = 'ssl';                 // sets the prefix to the server
$mail->Host       = 'smtp.gmail.com';      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = 'xxx@gmail.com';  // GMAIL username
$mail->Password   = 'yyy';            // GMAIL password
//End Gmail

$mail->From       = 'xxx@gmail.com';
$mail->FromName   = 'SYS';
$mail->Subject    = 'Registration Successful';
$mail->MsgHTML('You have successfully been added to the System!');

$mail->AddAddress($_POST['EmailAddress']);
$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {//to see if we return a message or a value bolean
    echo "Mailer Error: " . $mail->ErrorInfo;
} else  echo "Message sent!";

?>

这是我从中获取电子邮件地址的代码部分。我有它,以便用户将他的电子邮件地址输入文本框。它被保存为EmailAddress

AddUser.php:

<div class="">
<label style=""> Email Address </label>
<input id="Email Address" type="email" name="EmailAddress" value="">                          
</div>

我的sql查询在这里。我之后包含了Email.php文件。

<?php
.
.
.

include('./content/Email.php');
?>

这是我的按钮。当用户点击它时,信息将被存储并且应该发送电子邮件。

 </select></div>
 </div>
 </div> 

 <br><br>


 <input type="submit" class="btn btn-submit" value="Add User">

 </div>

0 个答案:

没有答案