Php 尝试从gmail.com发送电子邮件失败
我有一个名为contact.php的文件,里面有表单:Php 尝试从gmail.com发送电子邮件失败,php,smtp,pear,Php,Smtp,Pear,我有一个名为contact.php的文件,里面有表单: <form method="post" name="kontakt" action="send_mail.php"> <fieldset class="formularz_kontaktowy"> <legend>Formularz kontaktowy</legend> <div><label id="lblStatus"></label&g
<form method="post" name="kontakt" action="send_mail.php">
<fieldset class="formularz_kontaktowy">
<legend>Formularz kontaktowy</legend>
<div><label id="lblStatus"></label></div>
<div><input type="text" name="txtName" title="Imię i nazwisko" id="txtName" class="text"></div>
<div><input type="text" name="txtEmail" title="Email" id="txtEmail" class="text"></div>
<div><input type="text" name="txtTitle" title="Tytuł" id="txtTitle" class="text"></div>
<div><textarea cols="30" rows="10" name="txtMessage" id="txtMessage" class="text" title="Treść wiadomości"></textarea></div>
<input type="submit" name="btnSendmail" value=Send">
</fieldset>
</form>
send_mail.php
<?php
require_once "Mail.php";
$from = "<mailaddress@gmail.com>";
$to = "<mail2@gmail.com>";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "<mailaddress@gmail.com>";
$password = "password";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>
在浏览器中单击btnSendmail后,我有了URL,例如:localhost/contact.php?txtName=Mary+Smith&txtmail=mailMail%40gmail.com&txtitle=dfd&txtMessage=fgdf&btnSendmail=Send,但邮件没有发送,我没有消息。为什么?试着改变一下
$username = "<mailaddress@gmail.com>";
我发现了问题。我有两个标记,一个在模板中,另一个嵌套在contact.php中。非常感谢您的帮助。这需要先进行基本调试。请执行错误报告~0;ini设置“显示错误”,1;在你剧本的开头。此外,您应该查看并遵循错误日志。浏览器中的url不是发布表单以发送_mail.php的结果。你发布了你的原始代码吗?是的,这是我的原始代码,我只将登录/密码更改为mail
$username = "mailaddress@gmail.com";