Last active
December 17, 2015 13:17
-
-
Save takuya-andou/8addfcdd2dc2522aea1a to your computer and use it in GitHub Desktop.
How to mail via Gmail' SMTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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