我正在学习编码插件。
我试图在插件页面中创建一个表单,它可以发送邮件。
这是我的代码,但它不起作用(我没有收到电子邮件,也没有显示任何错误)。
add_action(\'admin_menu\', \'add_contact_us_page\');
function add_contact_us_page() {
add_menu_page(
__( \'Contact Us\', \'textdomain\' ),
__( \'Contact Us\',\'textdomain\' ),
\'manage_options\',
\'support_form_page\',
\'support_form\',
\'\'
);
}
function support_form() {
?>
<form action="" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name"><br>
E-mail:<br>
<input type="text" name="email"><br>
Message:<br>
<input type="text" name="message" size="50"><br><br>
<input type="submit" value="save">
</form>
<?php
}
if ( isset($_POST["submit"])) {
do_action(\'my_phpmailer_example\');
}
add_action( \'phpmailer_init\', \'my_phpmailer_example\' );
function my_phpmailer_example( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = \'smtp.sendgrid.net\';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 587;
$phpmailer->Username = \'****\';
$phpmailer->Password = \'****\';
$phpmailer->SMTPSecure = "tls";
$phpmailer->From = "you@yourdomail.com";
$phpmailer->FromName = "Your Name";
$phpmailer->Subject = "Subject Text";
$phpmailer->Body = "<i>Mail body in HTML</i>";
$phpmailer->AltBody = "This is the plain text version of the email content";
$phpmailer->AddAddress("my@mail.com", "name");
$phpmailer->SMTPDebug = true;
$smtp_debug = ob_get_clean();
if(!$phpmailer->send())
{
echo "Mailer Error: " . $phpmailer->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
echo $smtp_debug;
}
}
请帮忙,谢谢!