2013-10-02 3 views
19

Ich versuche, eine E-Mail von localhost zu meinem Yahoo Account mit php mail() -Funktion zu senden, die Rückkehr sagt, dass ich die E-Mail erfolgreich gesendet habe, aber ich habe keine E-Mail erhalten . Ich habe viele so genannte "einfache Wege" gelesen und versucht, E-Mails zu verschicken, aber das Ergebnis ist enttäuschend, nichts davon funktioniert für mich. Im Folgenden finden Sie den Code, die Konfigurationen und die Fehlermeldung. Kann mich jemand damit aufklären? Vielen Dank.Senden Sie eine E-Mail von localhost XAMMP in PHP mit GMAIL Mail-Server

PHP-Code

<?php 
$to  = '[email protected]'; 
$subject = 'Fake sendmail test'; 
$message = 'If we can read this, it means that our fake Sendmail setup works!'; 
$headers = 'From: [email protected]' . "\r\n" . 
      'Reply-To: [email protected]' . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 

if(mail($to, $subject, $message, $headers)) { 
    echo 'Email sent successfully!'; 
} else { 
    die('Failure: Email was not sent!'); 
} 
?> 

Konfiguration für php.ini (Ich bin mit gmail-Mail-Server)

SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = myemail @ gmail.com
sendmail_path = "\" C: \ xampp \ sendmail \ sendmail.exe \ "-t"

Konfiguration für sendmail.ini

smtp_server = smtp.gmail.com
smtp_port = 587
smtp_ssl = tls
error_logfile = error.log
debug_logfile = debug.log
auth_username = myemail @ gmail.com
AUTH_PASSWORD = mypassword
[email protected]

Fehlermeldung in Sendmail-Fehlerprotokoll mit Port 587

13/10/02 13:36:41: Muss zuerst einen STARTTLS-Befehl ausgeben. k4sm129639pbd.11 - gsmtp

+0

Ein Detail Blog: http://goo.gl/O1zw89 –

Antwort

19

Here's der Link, der mir die Antwort gibt:

[Install] die "fake sendmail for windows". Wenn Sie nicht XAMPP verwenden, können Sie es hier herunterladen: http://glob.com.au/sendmail/sendmail.zip

[Modify] the php.ini file to use it (commented out the other lines): 

[mail function] 
; For Win32 only. 
; SMTP = smtp.gmail.com 
; smtp_port = 25 

; For Win32 only. 
; sendmail_from = <e-mail username>@gmail.com 

; For Unix only. You may supply arguments as well (default: "sendmail -t -i"). 
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t" 

(ignorieren Sie die „Unix nur“ wenig, da wir tatsächlich send verwenden)

Sie dann die konfigurieren müssen "sendmail.ini" Datei in dem Verzeichnis, in dem send~~POS=TRUNC installiert wurde:

[sendmail] 

smtp_server=smtp.gmail.com 
smtp_port=25 
error_logfile=error.log 
debug_logfile=debug.log 
auth_username=<username> 
auth_password=<password> 
force_sender=<e-mail username>@gmail.com 

Um ein Google Mail-Konto zugreifen prote Bei der 2-Faktor-Verifizierung müssen Sie eine application-specific password erstellen. (source)

+0

Nur eine Bestätigung, dass dieses große Werk (sehen es nicht als Antwort ausgewählt wurde). – Foxhoundn

+3

Ich denke, dass Google Mail jetzt ssl benötigt – happyhardik

+0

Ich habe nach dieser Konfiguration Details über 2 Tage gesucht, danke Mann, hat dieser Beitrag mir wirklich geholfen, Problem zu lösen :). – DDeme

0
require_once "Mail.php"; 

$from = '<from.gmail.com>'; 
$to = '<to.yahoo.com>'; 
$subject = 'Hi!'; 
$body = "Hi,\n\nHow are you?"; 

$headers = array(
    'From' => $from, 
    'To' => $to, 
    'Subject' => $subject 
); 

$smtp = Mail::factory('smtp', array(
     'host' => 'ssl://smtp.gmail.com', 
     'port' => '465', 
     'auth' => true, 
     'username' => '[email protected]', 
     'password' => 'passwordxxx' 
    )); 

$mail = $smtp->send($to, $headers, $body); 

if (PEAR::isError($mail)) { 
    echo('<p>' . $mail->getMessage() . '</p>'); 
} else { 
    echo('<p>Message successfully sent!</p>'); 
} 
+2

Sie können Mail.php von hier herunterladen http://pear.php.net/package/Mail/download/ es funktioniert gut –

3

in php.ini-Datei, Kommentar- diese ein

sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t" 
;sendmail_path="C:\xampp\mailtodisk\mailtodisk.exe" 

und in sendmail.ini

smtp_server=smtp.gmail.com 
smtp_port=465 
error_logfile=error.log 
debug_logfile=debug.log 
[email protected] 
auth_password=yourpassword 
[email protected] 
hostname=localhost 

configure diese one..it Arbeiten werden ... es für mich gut funktioniert.

danke.

+0

Korrekte One..Danks viel .. – Jana

+0

Es hat für mich funktioniert. Ich musste mein Google Mail-Konto nur auf "Weniger sichere Apps zulassen: Ein" konfigurieren. Vielen Dank. – Zanoldor

0
[sendmail] 

smtp_server=smtp.gmail.com 
smtp_port=25 
error_logfile=error.log 
debug_logfile=debug.log 
[email protected] 
auth_password=gmailpassword 
[email protected] 

müssen Benutzername und Passwort von E-Mail authentifizieren dann nur einmal erfolgreich aus Mail senden localhost

0

Vergessen Sie nicht, ein zweites Passwort für Ihr Google Mail-Konto zu generieren. Sie werden dieses neue Passwort in Ihrem Code verwenden. Lesen Sie dazu:

https://support.google.com/accounts/answer/185833

Unter dem Abschnitt „Wie ein App-Passwort generieren“ klicken Sie auf „App-Passwörter“, dann unter „Select App“ wählen „Mail“, wählen Sie Ihr Gerät und klicken Sie auf „Generieren“. Ihr zweites Passwort wird auf dem Bildschirm ausgedruckt.

0

Ihre Spam überprüfen -

require 'PHPMailer/PHPMailerAutoload.php'; 
$mail = new PHPMailer; 

$mail->isSMTP();        
$mail->Host = 'smtp.gmail.com';    
$mail->SMTPAuth = true;      
$mail->Username = 'Email Address';   
$mail->Password = 'Email Account Password'; 
$mail->SMTPSecure = 'tls';    
$mail->Port = 587;     

Beispiel Skript und Code vollständige Quelle kann von hier. Die Funktion mail() sendet die Mail manchmal an Spam.

+0

Ja, Sie müssen die IP des Servers zum DNS hinzufügen – Skatox

0

VERSUCH DIESES. ES FUNKTIONIERT IMMER FÜR MICH.

$config['protocol'] = 'smtp'; 
    $config['smtp_host'] = 'ssl://smtp.gmail.com'; 
    $config['smtp_port'] = '465';       //ssl 
    $config['smtp_timeout'] = '7'; 
    $config['smtp_user'] = '[email protected]'; 
    $config['smtp_pass'] = 'pentium409'; 
    $config['charset'] = 'utf-8'; 
    $config['newline'] = "\r\n"; 
    $config['mailtype'] = 'html'; 
    $config['validation'] = TRUE;