I have been looking at multiple examples including this one.
I get the email no problem but there are no attachments. Am I missing the content/type of file type? All the examples I've seen uses only text/html as the content type.
Here's what I have (added upon Stephen's request)
if( isset( $_POST['to'] ) && isset( $_POST['from'] ) ) {
global $wpdb;
$to = $_POST['to'];
$from = $_POST['from'];
$name = get_bloginfo('name');
$attachment = $_POST['file'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: multipart/mixed; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $name . ' <' . $from . '>' . "\r\n";
$subject = 'Send to Kindle';
$msg = 'Yay! Your book has <a href="">arrived</a>';
$mail_attachment = array( $attachment );
wp_mail($to, $subject, $msg, $headers, $mail_attachment);
echo 'Email sent';
} else {
echo 'Email not sent';
}
I have been looking at multiple examples including this one.
I get the email no problem but there are no attachments. Am I missing the content/type of file type? All the examples I've seen uses only text/html as the content type.
Here's what I have (added upon Stephen's request)
if( isset( $_POST['to'] ) && isset( $_POST['from'] ) ) {
global $wpdb;
$to = $_POST['to'];
$from = $_POST['from'];
$name = get_bloginfo('name');
$attachment = $_POST['file'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: multipart/mixed; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $name . ' <' . $from . '>' . "\r\n";
$subject = 'Send to Kindle';
$msg = 'Yay! Your book has <a href="http://yahoo">arrived</a>';
$mail_attachment = array( $attachment );
wp_mail($to, $subject, $msg, $headers, $mail_attachment);
echo 'Email sent';
} else {
echo 'Email not sent';
}
Share
Improve this question
edited Apr 17, 2019 at 13:04
butlerblog
5,1313 gold badges28 silver badges44 bronze badges
asked Apr 26, 2012 at 3:59
tbmtbm
1771 gold badge2 silver badges8 bronze badges
2
- Could you post some code regarding what you've tried? – Stephen Harris Commented Apr 26, 2012 at 7:49
- Hi Stephen, just updated the post with the code. Thank you! – tbm Commented Apr 26, 2012 at 18:31
1 Answer
Reset to default 31The $attachment
argument for wp_mail
takes a file (or array of files) - but the file path has to be fully specified. For example:
<?php
$attachments = array(WP_CONTENT_DIR . '/uploads/file_to_attach.zip');
$headers = 'From: My Name <[email protected]>' . "\r\n";
wp_mail('[email protected]', 'subject', 'message', $headers, $attachments);
?>
(see Codex). It seems that your $_POST['file']
is probably not specifying the full path.
The attachment has to a file path, not an url. The following worked for me:
$to = $_POST['to'];
$from = $_POST['from'];
$name = get_bloginfo('name');
$headers = 'From: My Name <[email protected]>' . "\r\n";
$subject = 'Send to Kindle';
$msg = 'Yay! Your book has <a href="http://yahoo">arrived</a>';
$mail_attachment = array(WP_CONTENT_DIR . '/uploads/2012/03/image.png');
wp_mail($to, $subject, $msg, $headers, $mail_attachment);
Note: I changed the headers
attribute too. I'm not entirely sure what you're example was trying to do, but it meant the message of the email was not visible on some email clients.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745579893a4634189.html
评论列表(0条)