Php邮件发送邮件

时间:2017-04-20 20:30:49

标签: php html phpmailer

<div class="container">
          <form id="signup" method="post" action="<?php $_PHP_SELF ?>">
              <h1>Join US!.</h1>
              <input type="email" placeholder="sampleemail@gmail.com" name="userEmail"  required="">

              <input value="Sign up for free!" type="submit" style="background-color: #98FB98"></input>


          </form>
        </div> 

我在我的页面或用户界面中有这个代码,当用户输入电子邮件时如何使用PHPMailer将输入的电子邮件放入我的消息中,我有使用PHPMailer邮寄的代码。我尝试使用帖子,但它不起作用(抱歉我的英语不好)

<?php 
    require 'PHPMailerAutoload.php';
    include 'util/completeregvalidation.php';
$mail = new PHPMailer;

//$mail->SMTPDebug = 3;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';                       // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'sample@gmail.com';                 // SMTP username
$mail->Password = 'sampleacc';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom($emailval, 'Mailer');
$mail->addAddress('vega.residences@gmail.com', 'Joe User');     // Add a recipient
//$mail->addAddress('ellen@example.com');               // Name is optional
//$mail->addReplyTo('info@example.com', 'Information');
//$mail->addCC('cc@example.com');
//$mail->addBCC('bcc@example.com');

//$mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Confirm Registration';
$mail->Body    = "Please confirm registration.". ($_POST['userEmail']);

$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->send()) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    header('Location: ../pages/checkemail.php');
}
    ?>

这是我在phpmailer中的代码。

0 个答案:

没有答案