【发布时间】:2014-10-29 07:24:47
【问题描述】:
我对这个领域真的很陌生。我正在研究我的投资组合。我已经为 “联系我” 制作了模态联系表(引导程序)。我的 gmail 帐户没有收到来自 php 的邮件。我正在使用 PHP 邮件程序,以下是我的 php 代码,文件名为 contact-form.php:
<?php
// check for form submission - if it doesn't exist then send back to contact form**
if (!isset($_POST['submit'])) {
$message=
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
Message: '.$_POST['contact-message'];
require "phpmailer/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Set up SMTP connection
$mail->SMTPAuth = true; // Connection with SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host ="smtp.gmail.com"; //Gmail SMTP address
$mail->Port = 465; // Gmail SMTP port No idea what this is suppose to be
$mail->Encoding ='7bit';
$mail->Username = "mygmailid@gmail.com"; // Gmail address
$mail->Password ="Password"; // Gmail Password
// Compose
$mail->SetFrom($_POST['email'],$_POST['name']);
$mail->AddReplyTo($_POST['email'],$_POST['name']);
$mail->Subject = "Mail from Portfolio";
$mail->MsgHTML($message);
//Send To
$mail->AddAddress("recipientmail@gmail.com", "Recipient Name");
$result = $mail->Send();
$message = $result ? 'Successfully Sent!' : 'Sending Failed';
unset($mail);
}
我已将我所有的 html 页面与 contact-form.php 链接为:
<form action="contactform.php" class="form-horizontal" method="post" enctype="text/plain">
当我点击发送消息按钮时,它会将我引导至contact-form.php,但没有任何反应。
请帮帮我,自上周以来,我一直陷入这个问题。
任何建议或帮助都将不胜感激。
提前谢谢你:) 塔亚巴。
【问题讨论】:
-
你能做一些调试输出来验证数据是否传输到这个表单?
-
正如我所说,我是这个领域的新手,您能详细说明您的问题吗?谢谢
-
我看过下面的视频link
-
例如,在
if (!isset($_POST['submit'])) {条件中添加一些echo "something",以便您知道代码是否已执行。然后检查你的$message变量的内容是成功还是失败