我的文件名为contact.php,里面有表格:
<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
后我有了网址,例如:localhost/contact.php?txtName=Mary+Smith&txtEmail=mailMail%40gmail.com&txtTitle=dfd&txtMessage=fgdf&btnSendmail=Send
,但邮件没有发送,我没有留言。为什么呢?
答案 0 :(得分:0)
尝试更改
$username = "<mailaddress@gmail.com>";
到
$username = "mailaddress@gmail.com";
答案 1 :(得分:0)
我发现了问题。我有两个标签,一个在模板中,另一个嵌套在contact.php中。非常感谢您的帮助。