Search
 
SCRIPT & CODE EXAMPLE
 

PHP

send email in php

<?php
    ini_set( 'display_errors', 1 );
    error_reporting( E_ALL );
    $from = "test@hostinger-tutorials.com";
    $to = "test@hostinger.com";
    $subject = "Checking PHP mail";
    $message = "PHP mail works just fine";
    $headers = "From:" . $from;
    if(mail($to,$subject,$message, $headers)) {
		echo "The email message was sent.";
    } else {
    	echo "The email message was not sent.";
    }
Comment

php mail

<?php
    mail("recipient@example.com",
        "This is the message subject",
        "This is the message body",
        "From: sender@example.com" . "
" . "Content-Type: text/plain; charset=utf-8",
        "-fsender@example.com");
?>
Comment

sendMail php

<?php
require_once "Mail.php";

$from = "Sandra Sender <sender@example.com>";
$to = "Ramona Recipient <ramona@microsoft.com>";
$subject = "Hi!";
$body = "Hi,

How are you?";

$host = "smtp.gmail.com";
$port = "587";
$username = "testtest@gmail.com";
$password = "testtest";

$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

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

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

send-email.php

<?php

$name = $_POST["name"];
$email = $_POST["email"];
$subject = $_POST["subject"];
$message = $_POST["message"];

require "vendor/autoload.php";

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;

$mail = new PHPMailer(true);

// $mail->SMTPDebug = SMTP::DEBUG_SERVER;

$mail->isSMTP();
$mail->SMTPAuth = true;

$mail->Host = "smtp.example.com";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->Port = 587;

$mail->Username = "you@example.com";
$mail->Password = "password";

$mail->setFrom($email, $name);
$mail->addAddress("dave@example.com", "Dave");

$mail->Subject = $subject;
$mail->Body = $message;

$mail->send();

header("Location: sent.html");
Comment

php mail

mnjah
Comment

PREVIOUS NEXT
Code Example
Php :: php get all array keys in json 
Php :: php apply function to array elements 
Php :: wordpress if is not page template 
Php :: function inside model laravel 
Php :: what is abstract class in php 
Php :: seprate day and year from laravel to timestamp 
Php :: get query string in symfony twig 
Php :: if user name is wordpress 
Php :: htaccess redirect https laravel 
Php :: how to include javascript in php 
Php :: laravel chunk 
Php :: laravel validation types 
Php :: switch php version ubuntu 20.04 
Php :: laravel faker values 
Php :: php get property with ~ 
Php :: php count days excluding weekends 
Php :: how to use include in php 
Php :: how to print on console with phpunit 
Php :: how to set up alert messages in laravel 8 
Php :: Image not found or type unknown in pdf 
Php :: php get variable by string name 
Php :: extend woocommerce user fields edit-account 
Php :: substr php 
Php :: insert into database with seeder 
Php :: wordpress popular posts query 
Php :: php iterate through a loop 
Php :: array_unshift 
Php :: how to install apache mysql php on ubuntu 18.04 
Php :: Diferencia entre dias PHP - Con date_diff() 
Php :: file upload in laravel 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =