wp_mail() success sent when it is not using header ‘content-type:text/html’
-
I’ve been trying to use all the source that can possibly help my problem but it’s just not working well.
and this is my code:
$subject = 'Pendaftaran Paytren (Daftar-Paytren.net)'; $emaile = 'yukdaftarpaytren@gmail.com'; $message = 'Ada yang daftar<br/>Nama Lengkap : '.$nama.'<br/>Tempat Lahir : '.$tempatlahir.'<br/>Tanggal Lahir : '.$tanggallahir.'<br/>Jenis Kelamin : '.$jeniskelamin.'<br/>Negara : '.$negara.'<br/>Kota Tampat Tinggal : '.$kota.'<br/>Nomor HP : '.$telp.'<br/>Email : '.$email.'<br/>Username : '.$username.'<br/>Pin BB : '.$bb.'<br/>WA : '.$wa; $headers = array('Content-Type: text/html; charset=UTF-8', 'From: Daftar-Paytren.net <yukdaftarpaytren@gmail.com>'); if (wp_mail( $emaile, $subject, $message, $headers )){ echo "success"; }else { echo wp_mail( $emaile, $subject, $message, $headers ); }
and it was said success as if, but I wasn’t receive any mail in my inbox. but if I remove the headers ‘Content-type:’ thing, so the code will be:
$subject = 'Pendaftaran Paytren (Daftar-Paytren.net)'; $emaile = 'yukdaftarpaytren@gmail.com'; $message = 'Ada yang daftar<br/>Nama Lengkap : '.$nama.'<br/>Tempat Lahir : '.$tempatlahir.'<br/>Tanggal Lahir : '.$tanggallahir.'<br/>Jenis Kelamin : '.$jeniskelamin.'<br/>Negara : '.$negara.'<br/>Kota Tampat Tinggal : '.$kota.'<br/>Nomor HP : '.$telp.'<br/>Email : '.$email.'<br/>Username : '.$username.'<br/>Pin BB : '.$bb.'<br/>WA : '.$wa; $headers = 'From: Daftar-Paytren.net <yukdaftarpaytren@gmail.com>' . "\r\n"; if (wp_mail( $emaile, $subject, $message, $headers )){ echo "success"; }else { echo wp_mail( $emaile, $subject, $message, $headers ); }
and that’ll work and I receive the email but as plain text. I need to set the content type so the email can be read as well.
and I also tried this, still nothing work.
$headers[] = 'Content-Type: text/html; charset=UTF-8'; $headers[] = 'From: Daftar-Paytren.net <yukdaftarpaytren@gmail.com>' . "\r\n";
What is wrong with my code? please help me. and please ignore the language on that script.
UPDATE
if I used this code:
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' ); $emaile = 'yukdaftarpaytren@gmail.com'; $subject = 'Pendaftaran Paytren (Daftar-Paytren.net)'; $message = 'Ada yang daftar<br/>Nama Lengkap : '.$nama.'<br/>Tempat Lahir : '.$tempatlahir.'<br/>Tanggal Lahir : '.$tanggallahir.'<br/>Jenis Kelamin : '.$jeniskelamin.'<br/>Negara : '.$negara.'<br/>Kota Tampat Tinggal : '.$kota.'<br/>Nomor HP : '.$telp.'<br/>Email : '.$email.'<br/>Username : '.$username.'<br/>Pin BB : '.$bb.'<br/>WA : '.$wa; $headers = 'From: Daftar-Paytren.net <yukdaftarpaytren@gmail.com>' . "\r\n"; if (wp_mail( $emaile, $subject, $message, $headers )){ echo "sukses"; }else { echo wp_mail( $emaile, $subject, $message, $headers ); } // Reset content-type to avoid conflicts -- https://core.trac.wordpress.org/ticket/23578 remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' ); function wpdocs_set_html_mail_content_type() { return 'text/html'; }
The email was sent and I was receiving an inbox but, it is sending the subject as file attachment (.txt) with plain text as the content.
- The topic ‘wp_mail() success sent when it is not using header ‘content-type:text/html’’ is closed to new replies.