Send email with SMTP with PHP authentication

From EN Ikoula wiki
⧼vector-jumptonavigation⧽ ⧼vector-jumptosearch⧽

en:Send email with SMTP with PHP authentication he:שלחו מייל עם SMTP עם PHP אימות ru:Отправить письмо с SMTP аутентификации PHP ja:PHP による認証と SMTP でメールを送信します。 ar:إرسال البريد الإلكتروني مع SMTP مع مصادقة بي إتش بي zh:发送电子邮件的 SMTP 与 PHP 认证 ro:Trimite e-mail cu SMTP cu PHP autentificare pl:Wyślij e-mail z SMTP z PHP uwierzytelniania de:Senden Sie e-Mail mit SMTP mit Authentifizierung PHP nl:Stuur e-mail met SMTP met PHP verificatie it:Inviare email con SMTP con autenticazione PHP pt:Enviar e-mail com SMTP com autenticação PHP es:Enviar correo electrónico con SMTP con autenticación de PHP fr:Envoyer un email avec authentification SMTP avec PHP

This article has been created by an automatic translation software. You can view the article source here.

In the context of the use of a shared hosting Ikoula, it is not possible to generate the sending email from a PHP script non-secure, our servers requiring SMTP authentication.

Via PHPmailer

Here is a code example using PHPmailer.

// exemple serveur windows ikoula
<?php  
  include("class.phpmailer.php");
  include("class.smtp.php");
  date_default_timezone_set("Europe/Paris"); 
  $mail             = new PHPMailer(); 
  $body             = "Test de PHPMailer."; 
  $mail->IsSMTP();
  $mail->SMTPAuth   = true;
  $mail->Host       = "mail.votredomaine.tld";  
  $mail->Port       = 25;
  $mail->Username   = "votre email";
  $mail->Password   = "mot de passe";        
  $mail->From       = "votre email"; //adresse d’envoi correspondant au login entré précédemment
  $mail->FromName   = "votre nom"; // nom qui sera affiché
  $mail->Subject    = "This is the subject"; // sujet
  $mail->AltBody    = "corps du message au format texte"; //Body au format texte
  $mail->WordWrap   = 50; // nombre de caractères pour le retour à la ligne automatique
  $mail->MsgHTML($body); 
  $mail->AddReplyTo("votre mail","votre nom");
  $mail->AddAttachment("./examples/images/phpmailer.gif");// pièce jointe si besoin
  $mail->AddAddress("adresse destinataire 1","adresse destinataire 2");
  $mail->IsHTML(true); // envoyer au format html, passer a false si en mode texte 
  if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
  } else {
    echo "Le message à bien été envoyé";
  } 
?>

Copy /Paste the code below in your file and customize the following elements :

$body = "PHPMailer test.";
body of the message to send. It can be text gross or in HTML.
$mail - >Host = "mail.votredomaine.tld ";
SMTP relay that will send your message
$mail - >Username = "your email ";
your e-mail address, which will also be used to identify the SMTP server
$mail - >Password = "password ";
votre password SMTP
$mail - >From = "your email ";
e-mail address that will appear as the sender
$mail - >FromName = "your name ";
sender's name
$mail - >Subject = "This is the subject ";
post subject
$mail - >AltBody = "body of the message in text format ";
body of the message in text format brut
$mail - >AddReplyTo ("your mail ","your name ");
default reply address
$mail->AddAttachment("./examples/images/phpmailer.gif");
attachment if necessary
$mail - >AddAddress ("ship-to address 1","ship-to address 2");
recipient (s)

Additional information

When you work with scripts to send emails, it is important to bear in mind that these are the first targets of misuse by spammers. It is therefore important that you secure your scripts as much as possible.

Our first recommendation is to not use your usual mail box. Prefer to use an address that will be exclusively for this purpose.

If you use the code above in a contact form, we recommend that you add a CAPTCHAs.




This article seemed you to be useful ?

0



You are not allowed to post comments.