2012-05-29 155 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