在我的网站上,我有一个简单的联系表格,但我无法弄清楚为什么我不能发送电子邮件。
HTML:
<form id="contactForm" method="post" action="js/sendmail.php" >
<fieldset>
<p><label for="name" class="label">Name*:</label>
<input type="text" name="name" id="Text1" class="input required" />
</p>
<p><label for="email" class="label">Email*: </label>
<input type="email" name="email" id="contact_email" class="input email required" />
<span class="input_feedback"></span>
</p>
<p>
<label class="label">Your message*: </label>
<textarea class="textarea required" name="message" rows="10" cols="50" ></textarea>
</p>
<p class="submitButtons">
<input type="submit" value="Send email" id="senEmail" class="button"/>
</p>
</fieldset>
</form>
PHP:
<?php
include('class.phpmailer.php');
include("class.smtp.php");
session_set_cookie_params('3600'); // 1 hour
session_start();
$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail = new PHPMailer(); // create a new object
$mail->SMTPDebug =2;
$mail->IsSMTP(); // send via SMTP
$mail ->Host = 'mrvnet.kundenserver.de';
$mail->Port= 465;
$mail->SMTPAuth = true;
$mail->Username = 'info@brightongatwicktransfer.com';
$mail->Password = '******';
$mail->SetFrom('myName@yahoo.com');
$mail->Subject = "Test";
$mail->Body = "Something";
$mail->AddAddress('info@brightongatwicktransfer.com');
if(!$mail->Send())
{ echo "Mailer Error: " . $mail->ErrorInfo;}
else
{ echo "Message has been sent";}
?>
我尝试使用'ssl'和'tls',但没有结果。
主机公司说主机是正确的,并要求我尝试587和25端口,但我总是收到同样的错误:
2013-12-04 11:40:00 SMTP错误:无法连接到服务器:连接尝试
失败,因为关联方在一段时间后没有正确回应,或者
建立的连接失败,因为连接的主机无法响应。 (10060)
SMTP connect()失败。邮件程序错误:SMTP连接()失败。
答案 0 :(得分:0)
不是PHP编码器,而是在这里:
$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail = new PHPMailer(); // create a new object
您在>>之后使用分配对象,这是无效的,您应该先分配它:
$mail = new PHPMailer(); // create a new object
$mail->SMTPSecure = "ssl";
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";