2012-05-29 100 views
0

有没有人知道我如何让phpmailer在上传的网站上工作。上传网站上的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 = "[email protected]"; // GMAIL username 
$mail->Password = "";   // GMAIL password 

$mail->From  = "[email protected]"; 
$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("[email protected]","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. 

回答

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> 

希望这有助于。如果任何人有关于如何使这个建议好让我知道:)

+0

谢谢,现在要睡觉,但会尽量在早上和汇报。 –

+0

在这方面有什么进展? – McAfeeJ