Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to mail via Gmail' SMTP
<?php
require_once ( 'PHPMailerAutoload.php' );
$subject = "タイトル";
$body = "メール本文";
$fromname = "誰から";
$from = "from@from.com";
$smtp_user = "gmailアカウント@gmail.com";
$smtp_password = "gmailのパス";
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPSecure = 'tls';
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->IsHTML(false);
$mail->Username = $smtp_user;
$mail->Password = $smtp_password;
$mail->SetFrom($smtp_user);
$mail->From = $fromaddress;
$mail->Subject = $subject;
$mail->Body = $body;
$mail->AddAddress($to);
if( !$mail -> Send() ){
$message = "Message was not sent<br/ >";
$message .= "Mailer Error: " . $mailer->ErrorInfo;
} else {
$message = "Message has been sent";
}
echo $message;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.