Utilisation de wp_mail avec des pièces jointes mais aucune pièce jointe reçue
-
-
Pourriez-vouspublier un code concernant ce que vous avezessayé?Could you post some code regarding what you've tried?
- 0
- 2012-04-26
- Stephen Harris
-
Salut Stephen,vient demettre àjour lemessage avec le code.Je vous remercie!Hi Stephen, just updated the post with the code. Thank you!
- 0
- 2012-04-26
- tbm
-
1 réponses
- votes
-
- 2012-04-27
L'argument
$attachment
pourwp_mail
prend unfichier (ou untableau defichiers) -mais le chemin dufichier doit êtreentièrement spécifié. Parexemple:<?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); ?>
( voir Codex ). Il semble que votre
$_POST['file']
ne spécifieprobablementpas le chemin complet.Lapiècejointe doit avoir un chemin defichier ,pas une URL. Ce qui suit afonctionnépourmoi:
$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.com">arrived</a>'; $mail_attachment = array(WP_CONTENT_DIR . '/uploads/2012/03/image.png'); wp_mail($to, $subject, $msg, $headers, $mail_attachment);
Remarque: J'ai égalementmodifié l'attribut
headers
. Jene saispasexactement ce que votreexempleessayait defaire,mais cela signifiait que lemessage de l'e-mailn'étaitpas visible sur certains clients demessagerie.The
$attachment
argument forwp_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.com">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.-
Merci Stephenpour le suivi ... ok `$ _Post ['file']`esten fait une URL vers lefichieret j'ai confirmé que l'URLest correcte.Est-ce acceptable?Thank you Stephen for following up... ok `$_Post['file']` is actually a URL to the file and I have confirmed the URL is correct. Is that acceptable?
- 0
- 2012-04-27
- tbm
-
Non,voir la réponsemise àjour :)Nope, see updated answer :)
- 0
- 2012-04-27
- Stephen Harris
-
Cela signifie queje nepeuxpas leur demander d'envoyer unepiècejointe hébergée ailleurs,parexemple.Amazon S3?J'avaispeur de ça.J'essaie simplement de donner auxgens lapossibilité d'envoyer un PDFpare-mail au Kindle directement àpartir d'unepage Web.Quoi qu'ilen soit,je vaisessayer celaplustardet faire un rapport.That means I can't have them send an attachment that is hosted elsewhere e.g. Amazon S3? I was afraid of that. I'm just trying to give people the option to email a PDF to Kindle directly from a web page. Anyhow I'll try this later and report back.
- 0
- 2012-04-27
- tbm
-
Vouspourriez lire lefichier distant,puis lejoindre?Il y a un [exempleici] (http://uk3.php.net/manual/en/function.mail.php#105661).La question de savoirexactement comment vouspouvez lefaire/lesmeilleurespratiques serait une questionpour SO.You could read the remote file, then attach it? There's an [example here](http://uk3.php.net/manual/en/function.mail.php#105661). Exactly how you can do it / best practise would be a question for SO.
- 0
- 2012-04-27
- Stephen Harris
-
Mercibeaucoup Stephen J'aiessayé votre solutionet cela afonctionné.Maintenant ...je doistrouver commentenvoyer unepiècejointe hébergée ailleurs.Mercipour lepointeur où chercher!Thank you so much Stephen I tried your solution and it did work. Now... I have to figure out how to send attachment hosted elsewhere. Thanks for the pointer where to look!
- 0
- 2012-04-28
- tbm
J'aiexaminéplusieursexemples,y compris celui-ci .
Je reçois l'e-mail sansproblèmemaisiln'y apas depiècesjointes. Suis-je absent du contenu/type detype defichier? Tous lesexemples quej'ai vusn'utilisent que dutexte/html commetype de contenu.
Voici ce quej'ai (ajouté à la demande de Stephen)