0

有人知道我如何让 phpmailer 在上传的网站上工作。

include("class.phpmailer.php");
include("class.smtp.php");

$mail             = new PHPMailer();

$body             = "You have been added to the University of Portsmouth project 
database. Your password is 
'".$_POST['Password']."' 
And your username is 
'".$_POST['Username']."'
please click the link below, login to the website, select account settings and change    
the password to become verified";


$mail->IsSMTP();
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "tsl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 25;                   // set the SMTP port

$mail->Username   = "projectnateabiola@gmail.com";  // GMAIL username
$mail->Password   = "";            // GMAIL password

$mail->From       = "projectnateabiola@gmail.com";
$mail->FromName   = "Nathan Abiola";
$mail->Subject    = "You have been added to the project database, this email is important";
$mail->AltBody    = "Please click"; //Text Body
$mail->WordWrap   = 50; // set word wrap

$mail->MsgHTML($body);

$mail->AddReplyTo("projectnateabiola@gmail.com","Webmaster");

$mail->AddAddress($_POST['Email'],"First Last");

$mail->IsHTML(true); // send as HTML

if(!$mail->Send()) {
 echo "Mailer Error: " . $mail->ErrorInfo;
} 

}
 }
}

该代码在离线时有效,但是一旦我上传它,当我提交它时会出现以下错误。我是否错过了一些你不能在线使用 phpmailer 的东西。是否有任何机构有任何潜在的替代方案。感谢您提供任何可能的帮助。

SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.
4

1 回答 1

0

我将它用于我的网站。它是网页上的一个表单,它调用 php 文件来发送电子邮件。我发现它有时在大学服务器上会出现问题,所以请记住这一点。

创建一个名为 mailto.php 的文件并将其粘贴(请注意,您需要输入正确的电子邮件地址)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form Submitted!</title>
</head>
<body>

<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email
{
//send email
$email = $_REQUEST['email'] ;
$subject = $_REQUEST['subject'] ;
$message = $_REQUEST['message'] ;
mail( "PUT YOUR EMAIL ADDRESS HERE", "Subject: $subject",
$message, "From: $email" );

echo "Your message has been sent successfully!";
}
else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mailform.php'>
Email: <input name='email' type='text' /><br />
Subject: <input name='subject' type='text' /><br />
Message:<br />
<textarea name='message' rows='15' cols='40'>
</textarea><br />
<input type='submit' />
</form>";
}
?>
</body>
</html>

然后把它放在你的html文件的正文中

   <form name="formcheck" onsubmit="return formCheck(this);" action="mailto.php"     method="post">
     <br />
     &nbsp;&nbsp;E-mail:&nbsp;  <input type="text" name="email" id="email" size="42" />
     <br />
     <br />
     <br/>
     &nbsp;&nbsp;Subject: <input type="text" name="subject" id="subject" size="42" />
     <br />
     <br />
     <br />

     &nbsp;&nbsp;Message:

     <br />
     &nbsp;&nbsp;<textarea rows="5" cols="40" name="message" id="message"></textarea>

     <br />
     <br />
     &nbsp;&nbsp;<input type="submit" onClick="return checkmail(this.form.email)" value="Submit" /><input type="reset" />
     </form>

希望这会有所帮助,如果有人对如何使它更好地提出建议,请告诉我:)

于 2012-05-29T22:37:16.860 回答