我想使用1按钮发送带有phpmailer的邮件。你能告诉我怎么做:
<?php
function send(){
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'myemail';
$mail->Password = '******';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('tryadi.tab@gmail.com', 'try adi');
$mail->addAddress('try.adi.baschara@gmail.com');
$mail->addAttachment('/var/tmp/file.tar.gz');
$mail->addAttachment('/tmp/image.jpg', 'new.jpg');
$mail->isHTML(true);
$mail->Subject = 'email';
$mail->Body = "email has been sent";
$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 {
$_SESSION['user_email']=$email;
$_SESSION['account_create'] = 'Akun Anda Telah Selesai Di Buat';
header("location:index.php");
}
}
?>
这是我的提交代码
<!DOCTYPE html>
<head>
<title>i</title>
</head>
<body>
<input type="submit" name="submit" value="Submit">
</body>
</html>
有人可以告诉我如何使用1按钮发送电子邮件吗?请告诉我怎么做。
答案 0 :(得分:0)
您所做的就是定义一个函数 - 您需要实际调用它,检查请求是否首先是表单提交:
<?php
if(isset($_POST['submit'])) {
send();
}
//your send function definition goes here
您还需要定义$email
变量 - 您正在使用它但从未定义它。
答案 1 :(得分:0)
首先将您的html更改为这样的形式,然后使用isset
提交检查表单提交 function send(){
.....
}
if(isset($_POST['submit'])){ send(); }
<form action="mail.php" method="post" >
<input type="submit" name="submit" value="Submit">
</form>