2013-06-24 3 views
14

Ich versuche, SMTP auf CodeIgniter einzurichten. Alles funktioniert gut und ich erhalte Erfolgsmeldung auf der Seite, dass die E-Mail ohne Fehler gesendet wird. Aber, E-Mail wird nicht zugestellt. HierSMTP auf CodeIgniter zeigt Erfolg, aber E-Mail wird nicht an Gmail-Konto übermittelt

ist der Code, dass ich benutze:

$config = Array(
'protocol' => 'smtp', 
'smtp_host' => 'ssl://smtp.googlemail.com', 
'smtp_port' => 465, 
'smtp_user' => '[email protected]', 
'smtp_pass' => '***', 
'mailtype' => 'html', 
'charset' => 'iso-8859-1', 
'wordwrap' => TRUE 
); 
$this->load->library('email', $config); 

$this->email->from('[email protected]', 'Explendid Videos'); 
$this->email->to('[email protected]'); 
$this->email->reply_to('[email protected]', 'Explendid Videos'); 


$this->email->subject('Explendid Video - Contact form'); 

$message = "Contact form\n\n"; 
$message .= "Name: ". $_POST['name'] . "\n"; 
$message .= "Phone: ". $_POST['phone'] . "\n"; 
$message .= "Email: ". $_POST['email'] . "\n"; 

$this->email->message($message); 

$this->email->send(); 

Was kann der Grund sein, dass E-Mail ist nicht tatsächlich geliefert.

Antwort

30

ändern es auf die folgenden:

$ci = get_instance(); 
$ci->load->library('email'); 
$config['protocol'] = "smtp"; 
$config['smtp_host'] = "ssl://smtp.gmail.com"; 
$config['smtp_port'] = "465"; 
$config['smtp_user'] = "[email protected]"; 
$config['smtp_pass'] = "yourpassword"; 
$config['charset'] = "utf-8"; 
$config['mailtype'] = "html"; 
$config['newline'] = "\r\n"; 

$ci->email->initialize($config); 

$ci->email->from('[email protected]', 'Blabla'); 
$list = array('[email protected]'); 
$ci->email->to($list); 
$this->email->reply_to('[email protected]', 'Explendid Videos'); 
$ci->email->subject('This is an email test'); 
$ci->email->message('It is working. Great!'); 
$ci->email->send(); 
+3

dank es funktionierte durch „ssl Wechsel: //smtp.googlemail.com "to" ssl: //smtp.gmail.com " –

+2

Das gibt mir' fsockopen(): php_network_getaddresses: getaddrinfo fehlgeschlagen: Name oder Dienst nicht bekannt. "Das Entfernen von' ssl: // 'vom Anfang der Adresse funktionierte. – machineaddict

+0

wird es funktioniert für hotmail/outlook als auch ?? – lazyme114

0

Haben Sie Ihre php.ini-Datei überprüft? Versuch es. Wenn nicht, dann könnten Sie vielleicht auch SPF ausprobieren. SPF oder Sender Policy Framework ist eine neue Technologie, die eine einfache Erkennung von Spam ermöglicht. Gmail ehrt SPF, sofern Sie diese E-Mails nicht manuell als Spam markieren. Unabhängig davon müssen Sie, wenn Sie E-Mails an eine andere Adresse erhalten haben, auch Gmail erreicht haben. Überprüfen Sie Ihren Spam gründlich, da Gmail selbst bei sehr hohem Spamverdacht keine E-Mails verwirft, sondern im Spam-Ordner landet.

Sie können einen SPF einrichten, der es Ihrem Webserver ermöglicht, E-Mails zu senden, die dazu führen, dass Gmail E-Mails akzeptiert, die von Ihrem Webserver als authentisch gesendet werden. Siehe http://www.mydigitallife.info/how-to-set-up-and-create-sender-policy-framework-spf-domain-dns-txt-record-with-wizard/ und einen Assistenten von Microsoft.

+0

E-Mail sind nicht im Spam-Ordner gehen –

0

können Sie dieses Skript ändern, zum Debuggen Problem,

$this->email->send(); 

zu

if($this->email->send()) 
{ 
    echo 'Your email was sent.'; 
} 

else 
{ 
    show_error($this->email->print_debugger()); 
} 
4

hier ist Arbeit für mich auf apache2 Server, ci 2.1.4: Es ist sehr einfach: zuerst erstellen Sie eine Datei namens email.php unter Ihrer Anwendung/co nfig Verzeichnis geben Sie dann den folgenden Code in ihnen ~>

<?php 
$config['protocol'] = 'smtp'; 
$config['smtp_host'] = 'ssl://smtp.gmail.com'; 
$config['smtp_port'] = '465'; 
$config['smtp_user'] = 'u'r gmail account'; 
$config['smtp_pass'] = 'password of u'r account'; 
$config['charset'] = 'utf-8'; 
$config['newline'] = "\r\n"; 
?> 

dann eine Datei email.php unter Anwendung/controllers Verzeichnis mit dem Namen erstellen Sie dann diesen Code eingeben ~>

<?php 
    class Email extends CI_Controller 
    { 

    function send() 
    { 
    // Loads the email library 
    $this->load->library('email'); 
    // FCPATH refers to the CodeIgniter install directory 
    // Specifying a file to be attached with the email 
    // if u wish attach a file uncomment the script bellow: 
    //$file = FCPATH . 'yourfilename.txt'; 
    // Defines the email details 
    $this->email->from('[email protected]', 'ur Name'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('Email Test'); 
    $this->email->message('Testing the email class.'); 
    //also this script 
    //$this->email->attach($file); 
    // The email->send() statement will return a true or false 
    // If true, the email will be sent 
    if ($this->email->send()) { 
    echo "you are luck!"; 
    } else { 
    echo $this->email->print_debugger(); 
    } 
    } 

    } 
    ?> 
2

ersetzen

$config['protocol'] = 'smtp'; 

zu

$config['protocol'] = 'sendmail'; 
+0

Das hat den Trick für mich. Einfach aber genial - danke! – Raymond

+0

Bitte fügen Sie einige Erklärung zu Ihrer Antwort, um es für andere Leser nützlicher zu machen. –

+0

Es funktionierte.Versuche mit vielen anderen Lösungen für Stunden, vielen Dank –

0

Verwenden Sie den folgenden Code

Und nicht zu zwei Sicherheitseinstellungen in Google nicht folgen können.

1) https://www.google.com/settings/security/lesssecureapps < < wiederum auf

2) https://accounts.google.com/b/0/DisplayUnlockCaptcha < < Klicken Sie weiter

** 2 Schritt Überprüfung deaktivieren, wenn Sie es aktiviert haben.

$config = Array(
     'protocol' => 'smtp', 
     'smtp_host' => 'ssl://smtp.gmail.com', 
     'smtp_port' => 465, 
     'smtp_user' => '[email protected]', //email id 
     'smtp_pass' => 'xxxxxxxxxxx',   // password 
     'mailtype' => 'html', 
     'charset' => 'iso-8859-1' 
    ); 
    $this->load->library('email', $config); 
    $this->email->set_newline("\r\n"); 

    $this->email->from('[email protected]','my name'); 
    $this->email->to("[email protected]"); // email array 
    $this->email->subject('email subject'); 
    $this->email->message("my mail body"); 

    $result = $this->email->send(); 


    show_error($this->email->print_debugger()); // for debugging purpose :: remove this once it works... 
0

Ich änderte nur den Code von RobinCominotto, um es in Office365 zu arbeiten.

PS: Ich habe es funktioniert, wenn Sie es in einen Controller setzen und diese Funktion genau so aufrufen. .! Wenn ich lege diese configs auf email.php (config-Datei) funktioniert nicht mehr :(

$ci = get_instance(); 
    $ci->load->library('email'); 
    $config['protocol'] = "smtp"; 
    $config['smtp_host'] = "smtp.office365.com"; 
    $config['smtp_port'] = "587"; 
    $config['smtp_user'] = "<HERE COMES YOUR EMAIL>"; 
    $config['smtp_pass'] = "<HERE COMES THE PASSWORD OF EMAIL>"; 
    $config['charset'] = "utf-8"; 
    $config['mailtype'] = "html"; 
    $config['newline'] = "\r\n"; 

    $ci->email->initialize($config); 

    $ci->email->from('<HERE COMES YOUR EMAIL>', 'Blabla'); 
    $list = array('<HERE COMES TO EMAIL>', '<HERE COMES TO EMAIL>'); 
    $ci->email->to($list); 
    $this->email->reply_to('<HERE COMES YOUR EMAIL>', 'Explendid Videos'); 
    $ci->email->subject('This is an email test'); 
    $ci->email->message('It is working. Great!'); 
    $ci->email->send(); 
    print_r($ci->email->print_debugger()); 
Verwandte Themen