This question already has an answer here:
PHPMailer.php
/** * SMTP hosts.
* Either a single hostname or multiple semicolon-delimited hostnames.
* You can also specify a different port
* for each host by using this format: [hostname:port]
* (e.g. "smtp1.example.com:25;smtp2.example.com").
* You can also specify encryption type, for example:
* (e.g. "tls://smtp1.example.com:587;ssl://smtp2.example.com:465").
* Hosts will be tried in order.
*
* @var string
*/
public $Host = 'smtp.umbler.com';
/**
* The default SMTP server port.
*
* @var int
*/
public $Port = 587;
/**
* The SMTP HELO of the message.
* Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find
* one with the same method described above for $Hostname.
*
* @see PHPMailer::$Hostname
*
* @var string
*/
public $Helo = 'publicamente.com.br';
/**
* What kind of encryption to use on the SMTP connection.
* Options: '', 'ssl' or 'tls'.
*
* @var string
*/
public $SMTPSecure = 'ssl';
/**
* Whether to enable TLS encryption automatically if a server supports it,
* even if `SMTPSecure` is not set to 'tls'.
* Be aware that in PHP >= 5.6 this requires that the server's certificates are valid.
*
* @var bool
*/
public $SMTPAutoTLS = true;
/**
* Whether to use SMTP authentication.
* Uses the Username and Password properties.
*
* @see PHPMailer::$Username
* @see PHPMailer::$Password
*
* @var bool
*/
public $SMTPAuth = true;
/**
* Options array passed to stream_context_create when connecting via SMTP.
*
* @var array
*/
public $SMTPOptions = [];
/**
* SMTP username.
*
* @var string
*/
public $Username = 'example@email.com';
/**
* SMTP password.
*
* @var string
*/
public $Password = 'example_password';
/**
* SMTP auth type.
* Options are CRAM-MD5, LOGIN, PLAIN, XOAUTH2, attempted in that order if not specified.
*
* @var string
*/
public $AuthType = '';
/**
* An instance of the PHPMailer OAuth class.
*
* @var OAuth
*/
protected $oauth;
Set this config, but have no idea why it's not working (Changed real credentials to examples)
sendmail.php
<?php
$settings = array(
"name" => "Name",
"email" => "example@domain.com",
);
require_once "phpmailer/contact_form.php";
contact_form.php
<?php
// Class
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
// Validate
if ( isset( $_POST[ 'email' ] ) || array_key_exists( 'email', $_POST ) ) :
// Message Settings
$message = array(
'name' => $_POST[ 'name' ],
'email' => $_POST[ 'email' ],
'company' => $_POST[ 'company' ],
'phone' => $_POST[ 'phone' ],
'message' => $_POST[ 'message' ],
'body' => '',
"alerts" => array(
"error" => 'Sua mensagem não pode ser enviada, tente novamente.',
"success" => 'Obrigado! A sua mensagem foi enviada com sucesso.',
),
);
$message[ 'body' ] .= '<b>Nome:</b> ' . $message[ 'name' ];
$message[ 'body' ] .= '<br><b>Email:</b> ' . $message[ 'email' ];
$message[ 'body' ] .= '<br><b>Empresa:</b> ' . $message[ 'company' ];
$message[ 'body' ] .= '<br><b>telefone:</b> ' . $message[ 'Phone' ];
$message[ 'body' ] .= '<br><br><b>Mensagem:</b><br>' . $message[ 'message' ];
// Include
require 'phpmailer/Exception.php';
require 'phpmailer/PHPMailer.php';
$mail = new PHPMailer( true );
try {
// Recipients
$mail->AddReplyTo( $message[ 'email' ], $message[ 'name' ] );
$mail->setFrom( 'admin@'. $_SERVER['SERVER_NAME'], $message[ 'name' ] );
$mail->addAddress( $settings[ 'email' ], $settings[ 'name' ] );
// Content
$mail->isHTML( true );
$mail->Subject = $message[ 'subject' ];
$mail->Body = $message[ 'body' ];
// Send
$mail->send();
// Success
echo '["success", "'. $message[ 'alerts' ][ 'success' ] .'"]';
} catch ( Exception $e ) {
// Error
echo '["error", "'. $message[ 'alerts' ][ 'error' ] .'"]';
}
endif;
I've tried to use $mail setting STMP and all credentials here in this file, but nothing happend, no output message
It is already taken from template, I thought that is more useful than just put $mail, but I don't know how to use it.
I'm trying to undestand reading those comments, but I'm not having success with it.