2012-11-26 14 views
6

Possible Duplicate:
Having trouble with PHPMailerPHPMailer भेज जीमेल smtp टाइमआउट

इसी तरह के सवाल के बहुत सारे हैं, लेकिन उनमें से कोई भी मुझे मदद की।

यहाँ मेरी स्क्रिप्ट जो PHPMailer exmaples में प्रदान की जाती है है:

require_once('../class.phpmailer.php'); 
//include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded 

$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch 

$mail->IsSMTP(); // telling the class to use SMTP 

try { 
    $mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->SMTPSecure = "ssl";     // sets the prefix to the servier 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->Port  = 465;     // set the SMTP port for the GMAIL server 
    $mail->Username = "[email protected]"; // GMAIL username 
    $mail->Password = "yourpassword";   // GMAIL password 
    $mail->AddReplyTo('[email protected]', 'First Last'); 
    $mail->AddAddress('[email protected]', 'John Doe'); 
    $mail->SetFrom('[email protected]', 'First Last'); 
    $mail->AddReplyTo('[email protected]', 'First Last'); 
    $mail->Subject = 'PHPMailer Test Subject via mail(), advanced'; 
    $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically 
    $mail->MsgHTML("some message"); 
    $mail->Send(); 
    echo "Message Sent OK</p>\n"; 
} catch (phpmailerException $e) { 
    echo $e->errorMessage(); //Pretty error messages from PHPMailer 
} catch (Exception $e) { 
    echo $e->getMessage(); //Boring error messages from anything else! 
} 

और यहाँ त्रुटि है:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) 
SMTP Error: Could not connect to SMTP host. 

कई सवाल में यह php_openssl extenstion जो मेरे सर्वर में सक्षम किया गया है सक्षम करने के लिए उल्लेख किया गया था। मैं भी वहाँ अपने सर्वर पोर्ट 25 और सरल mail() समारोह के साथ कोई समस्या नहीं है PHPMailer संस्करण 5.1

उपयोग कर रहा हूँ काम करता है ठीक

आपकी मदद

+0

एक ही सर्वर से होस्ट \ पोर्ट को पिंग करें, यदि उसके नेटवर्क समस्या –

+0

@ डैगन: कोई समस्या नहीं है। मैंने लोकलहोस्ट पर भी कोशिश की है, और एक ही समस्या है। मैंने कई महीने पहले इस दृष्टिकोण का उपयोग करके कई ईमेल भेजे थे और यह ठीक काम कर रहा था, लेकिन अब मैं भूल गया हूं कि कैसे ... – Aliweb

उत्तर

9

यहाँ एक काम कर उदाहरण है के लिए धन्यवाद:

require_once ('class.phpmailer.php'); // Add the path as appropriate 
    $Mail = new PHPMailer(); 
    $Mail->IsSMTP(); // Use SMTP 
    $Mail->Host  = "smtp.gmail.com"; // Sets SMTP server 
    $Mail->SMTPDebug = 2; // 2 to enable SMTP debug information 
    $Mail->SMTPAuth = TRUE; // enable SMTP authentication 
    $Mail->SMTPSecure = "tls"; //Secure conection 
    $Mail->Port  = 587; // set the SMTP port 
    $Mail->Username = '[email protected]'; // SMTP account username 
    $Mail->Password = 'MyGmailPassword'; // SMTP account password 
    $Mail->Priority = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low) 
    $Mail->CharSet  = 'UTF-8'; 
    $Mail->Encoding = '8bit'; 
    $Mail->Subject  = 'Test Email Using Gmail'; 
    $Mail->ContentType = 'text/html; charset=utf-8\r\n'; 
    $Mail->From  = '[email protected]'; 
    $Mail->FromName = 'GMail Test'; 
    $Mail->WordWrap = 900; // RFC 2822 Compliant for Max 998 characters per line 

    $Mail->AddAddress($ToEmail); // To: 
    $Mail->isHTML(TRUE); 
    $Mail->Body = $MessageHTML; 
    $Mail->AltBody = $MessageTEXT; 
    $Mail->Send(); 
    $Mail->SmtpClose(); 

    if ($Mail->IsError()) { 
    echo "ERROR<br /><br />"; 
    } 
    else { 
    echo "OK<br /><br />"; 
    } 
+0

ठीक काम करता है! धन्यवाद! लेकिन क्या याहू खातों का उपयोग कर मेल भेजने के लिए एक ही समाधान है? – Aliweb

+0

बस एसएमटीपी पैरामीटर को संशोधित करें। मैं उन्हें नहीं जानता, लेकिन आप उन्हें याहू में पा सकते हैं। –

संबंधित मुद्दे