簡體   English   中英

如何使用wp_mail在php中發送電子郵件

[英]How to send email in php with wp_mail

我到處都看到了類似的代碼在使用中,但是我無法使其正常工作...

$to = 'myeamil@gmail.com';
$subject = 'test';
$message = 'test';
$headers = 'just a test';
wp_mail( $to, $subject, $message, $headers );

我也嘗試過:

if (wp_mail( $to, $subject, $message )) {
    echo "success";
} else {
    echo "fail";
}

什么都不會打印。 我想念什么?

我不希望為此使用插件。

這與我的做法略有不同:

try {
    $sent = @wp_mail( $to, $subject, $message );
} catch (Exception $e) {
    error_log('oops: ' . $e->getMessage()); // this line is for testing only!
}

if ( $sent ) {
    error_log('hooray! email sent!'); // so is this one
} else {
    error_log('oh. email not sent.'); // and this one, too
}

哦,如果沒有正確設置,它將無法在localhost上運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM