私は自分のlocalhost上に非常に単純なHTML CSSとjavaScriptウェブサイトを持っています。私は非常に簡単な連絡フォームをしたいです。通常、これを達成するためにプラグインを使用してWordPressを使用し、プレーンなWebサイトに電子メールを手動で作成したことはありません。phpMailer - localhostは現在このリクエストを処理できません。
私はclass.phpmailper.phpファイルをhttps://github.com/PHPMailer/PHPMailer/blob/master/class.phpmailer.phpからダウンロードして、自分のサイトのルートに入れました。私の連絡先フォームで
私はシンプル
if(isset($_POST['submit'])){
}
を行うと、電子メールを送信してみてください。
サイト名ページは
envirofuel-再設計されて動作していない:私はページを送信]をクリックしたときに、私はちょうど言うしかし、私は私のワードプレスのウェブサイト上で使用するのと同じSMTPの詳細を入れています現在この要求を処理できません。
HTTPエラー500
これは、フォームが送信されたときに実行されるコードです:
if(isset($_POST['submit'])){
require_once('class.phpmailer.php');
$subject = 'test';
$body_of_your_email = 'hello test body';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 0;
// 0 = no output, 1 = errors and messages, 2 = messages only.
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = ""; // sets the prefix to the servier
$mail->Host = "I PUT MY SMTP HOST HERE"; // sets Gmail as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL
$mail->Username = "I PUT MY USERNAME HERE"; // Gmail username
$mail->Password = "I PUT MY PASSWORD HERE"; // Gmail password
$mail->CharSet = 'windows-1250';
$mail->SetFrom ('[email protected]', 'Example.com Information');
$mail->AddBCC ('[email protected]', 'Example.com Sales Dep.');
$mail->Subject = $subject;
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->Body = $body_of_your_email;
// you may also use $mail->Body = file_get_contents('your_mail_template.html');
$mail->AddAddress ('I PUT MY PERSONAL EMAIL HERE', 'Matthew');
// you may also use this format $mail->AddAddress ($recipient);
if(!$mail->Send())
{
$error_message = "Mailer Error: " . $mail->ErrorInfo;
} else
{
$error_message = "Successfully sent!";
}
}
任意のアイデア?
エラー500は、サーバーレベルのエラーです。ログは何を言っていますか?デバッグツールを実行していますか? – Webomatik
あなたのコードは、古くなったPHPMailerの例に基づいています。それを更新してください。取得しているエラー(Webサーバーのログに記録されます)は、おそらくSMTPクラスをロードしていないことになります。 – Synchro