請問能否用貴公司的主機以PHP發送email,能否提供範例程式?

這是 PHPMailer 的範例語法


< ?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '/var/www/vhosts/your.domain/www/phpmailer/src/Exception.php';
require '/var/www/vhosts/your.domain/www/phpmailer/src/PHPMailer.php';
require '/var/www/vhosts/your.domain/www/phpmailer/src/SMTP.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions
try {
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'your mailserver ip'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'from@your.domain'; // SMTP username
$mail->Password = 'xxxxxxxx'; // SMTP password
# $mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 25; // TCP port to connect to
$mail->setFrom('from@your.domain', 'from'); // Set mail from
$mail->addAddress('mailto@mailto.domain', 'mailto');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body in bold!';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}?>


Was this article helpful?

mood_bad Dislike 1
mood Like 0
visibility Views: 1154