OVH Community, votre nouvel espace communautaire.

phpMailer smtp


anthebest
16/06/2013, 19h21
Miracle

J'ai enfin réussi à envoyer un mail via smtp en revanche j'ai laissé tombé phpMailer j'y suis directement allé avec fsockopen

Si vous voulez le code (c'est juste un test il est biensur à améliorer )

Code PHP:
//Server Address
$SmtpServer="****";
$SmtpPort="587"//default
$SmtpUser="****";
$SmtpPass="****";
class 
SMTPClient
{

function 
SMTPClient ($SmtpServer$SmtpPort$SmtpUser$SmtpPass$from$to$subject$body)
{

$this->SmtpServer $SmtpServer;
$this->SmtpUser base64_encode ($SmtpUser);
$this->SmtpPass base64_encode ($SmtpPass);
$this->from $from;
$this->to $to;
$this->subject $subject;
$this->body $body;

if (
$SmtpPort == ""
{
$this->PortSMTP 25;
}
else
{
$this->PortSMTP $SmtpPort;
}
}

function 
SendMail ()
{
if (
$SMTPIN fsockopen ($this->SmtpServer$this->PortSMTP)) 
{
fputs ($SMTPIN"EHLO archus.fr"."\r\n"); 
$talk["hello"] = fgets $SMTPIN1024 ); 
fputs($SMTPIN"auth login\r\n");
$talk["res"]=fgets($SMTPIN,1024);
fputs($SMTPIN$this->SmtpUser."\r\n");
$talk["user"]=fgets($SMTPIN,1024);
fputs($SMTPIN$this->SmtpPass."\r\n");
$talk["pass"]=fgets($SMTPIN,256);
fputs ($SMTPIN"MAIL FROM: <".$this->from.">\r\n"); 
$talk["From"] = fgets $SMTPIN1024 ); 
fputs ($SMTPIN"RCPT TO: <".$this->to.">\r\n"); 
$talk["To"] = fgets ($SMTPIN1024); 
fputs($SMTPIN"DATA\r\n");
$talk["data"]=fgets$SMTPIN,1024 );
fputs($SMTPIN"To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
$talk["send"]=fgets($SMTPIN,256);
//CLOSE CONNECTION AND EXIT ... 
fputs ($SMTPIN"QUIT\r\n"); 
$talk["end"]=fgets($SMTPIN,1024);
fclose($SMTPIN); 
// 

return 
$talk;

}
?>

anthebest
16/06/2013, 16h38
merci mais de toute façon je ne peux pas utiliser mail(); en local, c'est aussi pour cela que je voudrai utiliser le smtp pour ne pas effectuer les tests quand c'est en ligne

Gaston_Phone
16/06/2013, 11h42
Citation Envoyé par anthebest
De plus est il possible d'utiliser des comptes mails spécifiques avec mail() ?
Extraits de : OVH - Tester l'envoi de mail avec un petit script PHP :
// adresse MAIL OVH liée à l’hébergement.

$from = "Adresse_Mail_Contact_site";
$headers .= "From: $from \n";

anthebest
16/06/2013, 11h25
Merci Gaston mais c'est un peu la solution de facilité et je suis là pour apprendre j'aimerai donc bien arriver à utiliser le smtp.
De plus est il possible d'utiliser des comptes mails spécifiques avec mail() ?

Gaston_Phone
16/06/2013, 11h03
@ anthebest, es-tu vraiment obligé d'utiliser le SMTP ?

Sinon il y a la fonction mail(); qui fonctionne très bien : OVH - Tester l'envoi de mail avec un petit script PHP.

anthebest
16/06/2013, 09h00
j'ai me même problème

fritz2cat
16/06/2013, 08h10
Essaie le port 5025

Attention, ce service d'envoi SMTP n'est pas fait pour ça, il y a des limites (100 envois par heure - plusieurs destinataires sont comptabilisés pour plusieurs envois)

Frédéric

anthebest
15/06/2013, 22h51
Merci pour vos réponses

j'ai avancé en changeant le port (587), mais je bloque encore

Code:
SMTP -> FROM SERVER:220 ns0.ovh.net ssl0.ovh.net. You connect to mail622.ha.ovh.net ESMTP
CLIENT -> SMTP: EHLO book.local
SMTP -> FROM SERVER: 250-ns0.ovh.net ssl0.ovh.net. You connect to mail622.ha.ovh.net250-AUTH LOGIN PLAIN250-AUTH=LOGIN PLAIN250-PIPELINING250-8BITMIME250 SIZE 109000000
CLIENT -> SMTP: STARTTLS
SMTP -> FROM SERVER:502 unimplemented (#5.5.1)
SMTP -> ERROR: STARTTLS not accepted from server: 502 unimplemented (#5.5.1)
CLIENT -> SMTP: quit
SMTP -> FROM SERVER:221 ns0.ovh.net ssl0.ovh.net. You connect to mail622.ha.ovh.net
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
c'est peut être du à
Vous devez aussi cocher l'option "serveur d'envoi/smtp requiert une authentification" (pas SSL ni cryptée) en utilisant les mêmes paramètres que pour le serveur entrant POP.

mais je ne trouve pas cette option

Daniel60
15/06/2013, 19h43
Bof, il/elle a dit : "je ne sais pas si c'est utile".
Bin non, évidemment

Gaston_Phone
15/06/2013, 19h01
Hum! Hum!
Quel rapport entre :
  • l'envoi de courriels depuis ton hébergement mutualisé via phpMailer
  • la configuration de ta BOX

Daniel60
15/06/2013, 18h48
Le port 25 n'est pas utilisable, cf http://guides.ovh.com/ConfigurationEmail

anthebest
15/06/2013, 12h25
Bonjour.

J'ai un mutualisé et j'essai d'envoyer un mail en utilisant phpMailer

Mon code:

Code PHP:
    public static function sendMail($params){
        
$ini unserialize(INI);

        
$defaults = array(
            
'SMTPDebug' => $ini['mail']['SMTPDebug'],
            
'Debugoutput' => $ini['mail']['Debugoutput'],
            
'Host' => $ini['mail']['Host'],
            
'Port' => $ini['mail']['Port'],
            
'SMTPSecure' => $ini['mail']['SMTPSecure'],
            
'SMTPAuth' => $ini['mail']['SMTPAuth'],
            
'Username' => $ini['mail']['Username'],
            
'Password' => $ini['mail']['Password'],
            
'From' => array($ini['mail']['Username'],$ini['application']['name']),
            
'Subject' => $ini['application']['name'],
            
'To' => array(),
            
'Attachement' => array(),
            
'Layout' => 'src/main/views/layouts/mail.php',
            
'Content' => ''

        
);

        
$params array_merge($defaults$params);

        
//Create a new PHPMailer instance
        
$mail = new PHPMailer();
        
//Tell PHPMailer to use SMTP
        
$mail->IsSMTP();
        
//Enable SMTP debugging
        // 0 = off (for production use)
        // 1 = client messages
        // 2 = client and server messages
        
$mail->SMTPDebug  $params['SMTPDebug'];
        
//Ask for HTML-friendly debug output
        
$mail->Debugoutput $params['Debugoutput'];
        
//Set the hostname of the mail server
        
$mail->Host       $params['Host'];
        
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
        
$mail->Port       $params['Port'];
        
//Set the encryption system to use - ssl (deprecated) or tls
        
$mail->SMTPSecure $params['SMTPSecure'];
        
//Whether to use SMTP authentication
        
$mail->SMTPAuth   $params['SMTPAuth'];
        
//Username to use for SMTP authentication - use full email address for gmail
        
$mail->Username   $params['Username'];
        
//Password to use for SMTP authentication
        
$mail->Password   $params['Password'];
        
//Set who the message is to be sent from
        
$mail->SetFrom($params['From'][0], $params['From'][1]);
        
        foreach(
$params['To'] as $to){
            
//Set who the message is to be sent to
            
$mail->AddAddress($to[0], $to[1]);
        }
        
        
//Set the subject line
        
$mail->Subject $params['Subject'];

        
//Read an HTML message body from an external file, convert referenced images to embedded, convert HTML into a basic plain-text alternative body

        
$mailLayout file_get_contents($params['Layout']);
        
$mailContent str_replace("%content%"$params['Content'], $mailLayout);
        
$mail->MsgHTML($mailContentdirname(__FILE__));

        
//Attach an image file
        
foreach ($params['Attachement'] as $key => $value) {
            
$mail->AddAttachment($value);
        }

        
//Send the message, check for errors
        
        
if(!$mail->Send()) {
          echo 
"Mailer Error: " $mail->ErrorInfo;
        } else {
          echo 
"Message sent!";
        }
        
        
    } 
et les config dans mon fichier ini

Code:
;Phpmailer
[mail]
;debug(0=>prod,1=>user,2=>user and server)
SMTPDebug = 2
Debugoutput = "html"
Host = "smtp.mondom.fr"
Port = 25
SMTPSecure = "tls"
SMTPAuth = true
Username = "test@mondom.fr"
Password = "xxxx"
je suis sur des valeurs pour Unername et Password ainsi que pour le Host

Je suis donc en local, j'ai ouvert le port 25 de ma box je ne sais pas si c'est utile

et j'ai donc l'erreur suivante

SMTP -> ERROR: Failed to connect to server: Operation timed out (60)
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.

J'ai regardé les forums, la seule réponse que j'ai trouvé est d'utiliser QMAIL mais je ne voudrai le faire en smtp.
Toutefois j'ai essayé avec QMAIL, $mail->Send() retourne true mais je ne reçois aucun mail il y a t'il un log mail sur les mutualisés ?

Merci