Search
 
SCRIPT & CODE EXAMPLE
 

PHP

send email php smtp hostinger

<?php
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
require './PHPMailer-master/src/Exception.php';
require './PHPMailer-master/src/PHPMailer.php';
require './PHPMailer-master/src/SMTP.php';
$html = "<h1>Hello </h1>";
$mail = new PHPMailer(true);
try {
    //Server settings
    $mail->isSMTP();                                          
    $mail->Host       = 'smtp.titan.email'; 
    $mail->SMTPAuth   = true;                                 
    $mail->Username   = 'contact@domain.com';               
    $mail->Password   = 'password';                           
    $mail->SMTPSecure = 'ssl';                                  
    $mail->Port       = 465;                                  

    //Recipients
    $mail->setFrom('contact@domain.com', 'domain Team');
    $mail->addAddress('receiver1@gmail.com', 'Joe User');    
    $mail->addAddress('receiver2@gmail.com', 'Joe User');    
    // Attachments
    // Content
    $mail->isHTML(true);                                 
    $mail->Subject = 'Here is the subject';
    $mail->Body    = $html;
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    $mail->send();
    echo true;

} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Comment

send email php smtp


I migrated an application to a platform without a local transport agent (MTA). I did not want to configure an MTA, so I wrote this xxmail function to replace mail() with calls to a remote SMTP server. Hopefully it is of some use.

function xxmail($to, $subject, $body, $headers)
{
 $smtp = stream_socket_client('tcp://smtp.yourmail.com:25', $eno, $estr, 30);

 $B = 8192;
 $c = "
";
 $s = 'myapp@someserver.com';

 fwrite($smtp, 'helo ' . $_ENV['HOSTNAME'] . $c);
  $junk = fgets($smtp, $B);

 // Envelope
 fwrite($smtp, 'mail from: ' . $s . $c);
  $junk = fgets($smtp, $B);
 fwrite($smtp, 'rcpt to: ' . $to . $c);
  $junk = fgets($smtp, $B);
 fwrite($smtp, 'data' . $c);
  $junk = fgets($smtp, $B);

 // Header 
 fwrite($smtp, 'To: ' . $to . $c); 
 if(strlen($subject)) fwrite($smtp, 'Subject: ' . $subject . $c); 
 if(strlen($headers)) fwrite($smtp, $headers); // Must be 
 (delimited)
 fwrite($smtp, $headers . $c); 

 // Body
 if(strlen($body)) fwrite($smtp, $body . $c); 
 fwrite($smtp, $c . '.' . $c);
  $junk = fgets($smtp, $B);

 // Close
 fwrite($smtp, 'quit' . $c);
  $junk = fgets($smtp, $B);
 fclose($smtp);
}
Comment

PREVIOUS NEXT
Code Example
Php :: string into integer php 
Php :: If a String Contains a Specific Word in PHP 
Php :: get order details by id woocommerce 
Php :: symfony get query param 
Php :: wp wordpress logout 
Php :: Missing expression. (near "ON" at position 25) 
Php :: sanitize user input php 
Php :: get current route in blade laravel 
Php :: display image in laravel 
Php :: update eloquent with increment laravel 
Php :: convert to int php 
Php :: read file data using php 
Php :: server error in laravel 
Php :: laravel get url path 
Php :: get array key php 
Php :: [DoctrineDBALDBALException]Unknown database type enum requested, DoctrineDBALPlatformsMySqlPlatform may not support it. 
Php :: php get text from html 
Php :: sort multidimensional array php by key 
Php :: laravel token logout 
Php :: ob_start in php 
Php :: get all artisan commands 
Php :: wordpress truncate text 
Php :: Class "AppUser" not found 
Php :: php get bearer token from request 
Php :: laravel conditional class 
Php :: laravel validation unique if this field is changed 
Php :: laravel validate enum field 
Php :: how validate if one parameter is exist another parameter must exist in laravel 
Php :: phpspreadsheet middle align 
Php :: php expire a session 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =