PDA

View Full Version : مشکل با php mailer



hamed72900
دوشنبه 28 اسفند 1391, 14:39 عصر
سلام

من برای فرم contact از phpmailer استفاده کردم ولی همش بهم این ارورو میده :

SMTP Error: Could not connect to SMTP host. Message could not be sent.
Mailer Error: SMTP Error: Could not connect to SMTP host.

اینم کدیه که میزنم :



<?php
require("phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = "465"; // SMTP Port
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure= "ssl"; // SMTP connection type
$mail->Username = "mygmail@gmail.com"; // SMTP username
$mail->Password = "mypass"; // SMTP password
// Send email to :
$mail->AddAddress("myid@yahoo.com"); // will receive the test email
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
echo <<<_END
<html>
<form method="post" action="">
<input type="text" name="subject" value="subject"/>
<input type="text" name="from" value="email"/>
<input type="text" name="name" value="name"/>
<input type="text" name="body" value="body"/>
<input type="submit" value="send"/>
</form>
</html>
_END;
?>


SOME BODY HEEEEEEEEELP MEEEEEEE

iradata
دوشنبه 28 اسفند 1391, 15:14 عصر
require_once('../class.phpmailer.php');
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded

$mail = new PHPMailer();

$body = file_get_contents('contents.html');
$body = eregi_replace("[\]",'',$body);

$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host = "mail.yourdomain.com"; // SMTP server
$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)
// 1 = errors and messages
// 2 = messages only
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "yourusername@gmail.com"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password

$mail->SetFrom('name@yourdomain.com', 'First Last');

$mail->AddReplyTo("name@yourdomain.com","First Last");

$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$address = "whoto@otherdomain.com";
$mail->AddAddress($address, "John Doe");

$mail->AddAttachment("images/phpmailer.gif"); // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

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

hamed72900
سه شنبه 29 اسفند 1391, 22:10 عصر
ممنون . ولی منم دقیقا همین کارارو میکنم و میخوام با tls و یا ssl جیمیل بفرستم ولی همش ارور میده . البته من اینو روی هاست اصلیم امتحان نکردم و فقط روی هاست رایگان گیگفا تست کردم و نشد .
به نظرتون احتمال داره به خاطر هاست باشه یا این کد اشکال داره ؟؟
و یه چیز دیگه ، پیشنهاد خودتون برای ارسال ایمیل چه روشیه ؟؟