我真的很喜欢这个领域。我正在研究我的投资组合。我为“联系我”制作了模态联系表(引导程序)。我没有从php获取我的Gmail帐户邮件。我正在使用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);
}
我已将 contact-form.php 的所有html网页链接为:
<form action="contactform.php" class="form-horizontal" method="post" enctype="text/plain">
当我点击发送消息按钮时,它指示我联系contact-form.php但没有发生任何事情。
请帮助我,自上周以来我一直陷入这个问题。
任何建议或帮助都会非常明显。
提前谢谢你:) Tayyaba。
答案 0 :(得分:0)
我感谢您目前使用的代码,因为很难调试代码,如果您使用静态信息测试代码会更好, 我在下面给出了一个工作示例:
$email = new PHPMailer();
$email->From = 'amrinder.salentro@gmail.com';
$email->FromName = 'Amrinder Singh';
$email->Subject = 'Hello';
$email->Body = "How are you karan";
$email->AddAddress( 'amrinder.salentro@gmail.com' );
$email->AddAttachment( 'PATH_OF_YOUR_FILE_HERE' , 'NameOfFile.pdf' ); //optional
return $email->Send();
我希望它会对你有所帮助。请跟着它...... 谢谢... :))
答案 1 :(得分:0)
首先,我建议您再次使用a known-good example通过gmail发送,并确保您使用的是最新的PHPMailer。至于你的脚本,这一行意味着你的邮件处理代码只会在表单 not 提交时才会运行,因为这会导致发送错误,你没有显示,你赢了# 39;看不到任何事情!
if (!isset($_POST['submit'])) {
这应该是:
if (isset($_POST['submit'])) {