2013-01-12 16 views
20

Ho lo stesso script php in esecuzione su localhost - il mio PC con XAMPP e su un server ospitato. Funziona dal mio PC, ma non dal server ospitato."Password non accettata dal server: 535 Dati di autenticazione errati" quando si invia con GMail e phpMailer

Quando trasmetto dal server ospitato, ottengo il seguente output:

SMTP -> ERROR: Password not accepted from server: 535 Incorrect authentication data 
SMTP -> ERROR: RCPT not accepted from server: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message. dev.camppage.com 550-(patchvalues.com) [205.234.141.238]:50958 is not permitted to relay through 550 this server without authentication. 
SMTP Error: The following recipients failed: [email protected] FAILED 

Ho il sospetto che ci sia un'impostazione di configurazione che deve essere modificato sul server, ma non so quale . Qualsiasi consiglio sarebbe molto apprezzato!

Ecco il codice:

function send_gmail ($recipients, $subject, $message, $attachment_filenames = array()) 
{ 
    global $email_address, $email_password, $email_name; 
    require_once ($_SERVER['DOCUMENT_ROOT']. '/php/PHPMailer/class.phpmailer.php'); 

    $body = $message; 
    $body = str_replace("\\", '', $body); 
    $mail = new PHPMailer(); 
    $mail->CharSet = "UTF-8"; 
    $mail->IsSMTP(); 
    $mail->Host  = "smtp.gmail.com";  // sets GMAIL as the SMTP server 
    $mail->SMTPDebug = 1;      // enables SMTP debug information (for testing) 0 - none; 1 - errors & messages; 2 - messages only 
    $mail->SMTPAuth = true;     // enable SMTP authentication 
    $mail->SMTPSecure = "ssl";     // sets the prefix to the servier 
    $mail->Port  = 465;     // set the SMTP port 
    $mail->Username = $email_address; // GMAIL username 
    $mail->Password = $email_password; // GMAIL password 
    $mail->SetFrom($email_address); 
    $mail->FromName = $email_name; 
    $mail->AddReplyTo($email_address,$email_name); 
    $mail->Subject = $subject; 
    $mail->MsgHTML($body); 
    $mail->IsHTML(true); // send as HTML 

    if (isset ($recipients[0])) 
    { 
    foreach ($recipients AS $to) 
    { 
     $to_pieces = explode (",", $to, 2); 
     $to_email = trim ($to_pieces[0]); 
     if (isset ($to_pieces[1])) 
      $to_name = trim ($to_pieces[1]); 
     else 
      $to_name = " "; 
     $mail->AddAddress($to_email, $to_name); 
    } 
    $mail->IsHTML(true); // send as HTML 

    if ($mail->Send()){ 
     return TRUE; 
    } else { 
     return FALSE; 
    } 
} 
else 
{ 
    return FALSE; 
} 
} 

TIA

risposta

43

La soluzione era quella di consentire SMTP in uscita dalle impostazioni del server.

Su server che eseguono WHM di cPanel, questo si trova nella sezione "Impostazioni Tweak" di WHM.

L'opzione è di abilitare/disabilitare - scegliere disattiva.

Avvertenza: questa modifica consente di reindirizzare le connessioni SMTP in uscita consentendo agli account di stabilire connessioni dirette che potrebbero aumentare le probabilità di ottenere il blacklist del server.

+8

Sei un risparmiatore di vita. Sto usando CentOs 6 'Accedi a CPanel> Impostazioni Tweak> Tutte> " Limita SMTP in uscita a root, exim e mailman (FKA SMTP Tweak) "' <== disabilitarlo. Descrivo più dettagli per chiunque abbia lo stesso problema –

+1

Amico, sei un risparmiatore di vita, ero proprio di fronte al plotone della frustrazione quando sei venuto dal nulla con il tuo eroe per salvarmi. Grazie – Temitayo

+0

Sì. Ho salvato anche la mia pelle. Grazie! –

Problemi correlati