如何在php中传递邮件功能

时间:2015-02-12 11:13:03

标签: php html css

我是php的新手,我想要在邮件功能中传递变量的解决方案 我使用这种方式来变量传递邮件功能,但是遇到问题代码:

<?php
require 'PHPMailer/PHPMailerAutoload.php';

function Send_Mail($to,$subject,$body,$cc = "",$bcc = "")
{
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = 'smtp.gmail.com';
    $mail->SMTPAuth = true;
    $mail->SMTPDebug = false;
    $mail->Username = 'xyz@gmail.com'; // Your Gmail Address
    $mail->Password = '123456'; // Your Gmail Password 
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;
    $mail->From = 'xyz@gmail.com'; // From Email Address
    $mail->FromName = 'gfgg'; // From Name
    $mail->addAddress($to);
    $mail->addReplyTo('xyz@gmail.com', 'dfg'); // Same as From Email and From Name.
    $mail->WordWrap = 50;
    $mail->isHTML(true);
    $mail->Subject = $subject;
    $mail->Body    = $body;
    if(!$mail->send()) {
       return array('status' => false, 'message' => $mail->ErrorInfo);
    }
    return array('status' => true, 'message' => 'Email Sent Successfully');
}

if (isset($_REQUEST['submit']))
{
   $name=$_POST['name'];
   $email=$_POST['email'];
   $contact=$_POST['contact'];
   echo $name, $email, $contact;
  $result = Send_Mail('$name','$email','$contact');

}

请给我解决     ?&GT;

2 个答案:

答案 0 :(得分:0)

尝试 -

echo "$name, $email, $contact";
$result = Send_Mail($name,$email,$contact);

答案 1 :(得分:0)

Send_Mail函数至少需要3个参数,按此顺序为$to$subject$body。 首先,您要在字符串中调用参数

$result = Send_Mail('$name','$email','$contact');

并且顺序错误。

你应该试试这个

$result = Send_Mail($email, "Subject", "Message");

您必须定义$ subject和$ message变量,并将其替换为“Subject”和“Message”