cocolembo Posted July 22, 2021 Share Posted July 22, 2021 (edited) Hello, Can someone help me with these contact-form please, I just want to include a file (.pdf, .jpg, .png) and send the mail. For the moment, the mail is send but not with the file included. Here is the website http://www.coeuraprendre.art HTML CODE : <form id="contact-form" class="checkform" action="#" target="contact-send.php" method="post" enctype="multipart/form-data" > <div class="form-row clearfix"> <label for="name" class="req">Nom *</label> <input type="text" name="name" class="name" id="name" value="" placeholder="Name" /> </div> <div class="form-row clearfix"> <label for="email" class="req">Email *</label> <input type="text" name="email" class="email" id="email" value="" placeholder="Email"/> </div> <div class="form-row clearfix textbox"> <label for="message" class="req">Nom du projet *</label> <textarea name="message" class="message" id="message" rows="15" cols="50" placeholder="Message"></textarea> </div> <div class="form-row clearfix"> <label for="pdf" class="req">Ajoutez votre dossier d'inscription (Pdf intéractif) *</label> <input type="file" id="pdf" class="pdf" name="pdf" placeholder="Pdf" accept="image/pdf"> </div> <div id="form-note"> <div class="alert alert-error"> <strong>Error</strong>: Please check your entries! </div> </div> <div class="form-row form-submit"> <input type="submit" name="submit_form" class="submit" value="Send" /> </div> <input type="hidden" name="subject" value="From Coeur à Prendre" /> <input type="hidden" name="fields" value="name,email,message," /> <input type="hidden" name="sendto" value="info@coeuraprendre.art" /> </form> </div> <!-- Contact form --> PHP CODE : <?php define("WEBMASTER_EMAIL", $_POST['sendto']); if (WEBMASTER_EMAIL == '' || WEBMASTER_EMAIL == 'Testemail') { die('<div class="alert alert-confirm"> <h6><strong>The recipient email is not correct</strong></h6></div>'); } define("EMAIL_SUBJECT", $_POST['subject']); if (EMAIL_SUBJECT == '' || EMAIL_SUBJECT == 'Subject') { define("EMAIL_SUBJECT",'Contact'); } $name = stripslashes($_POST['name']); $email = trim($_POST['email']); $message = stripslashes($_POST['message']); $pdf = stripslashes($_POST['pdf']); $custom = $_POST['fields']; $custom = substr($custom, 0, -1); $custom = explode(',', $custom); $message_addition = ''; foreach ($custom as $c) { if ($c !== 'name' && $c !== 'email' && $c !== 'message' && $c !== 'pdf' && $c !== 'subject') { $message_addition .= '<b>'.$c.'</b>: '.$_POST[$c].'<br />'; } } if ($message_addition !== '') { $message = $message.'<br /><br />'.$message_addition; } $message = '<html><body>'.nl2br($message)."</body></html>"; $mail = mail(WEBMASTER_EMAIL, EMAIL_SUBJECT, $message, "From: ".$name." <".$email.">\r\n" ."Reply-To: ".$email."\r\n" ."X-Mailer: PHP/" . phpversion() ."MIME-Version: 1.0\r\n" ."Content-Type: text/html; charset=utf-8"); if($mail) { echo ' <div class="alert alert-confirm"> <strong>Confirm</strong>: Your message has been sent. Thank you! </div> '; } else { echo ' <div class="alert alert-error"> <strong>Error</strong>: Your message has not been send! </div> '; } ?> Edited July 22, 2021 by cocolembo Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/ Share on other sites More sharing options...
gw1500se Posted July 22, 2021 Share Posted July 22, 2021 Where do you "addAttachement" and reference the uploaded file? I think you did not post your complete code. Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588494 Share on other sites More sharing options...
cocolembo Posted July 22, 2021 Author Share Posted July 22, 2021 8 minutes ago, gw1500se said: Where do you "addAttachement" and reference the uploaded file? I think you did not post your complete code. Yes I remove all the php code for the implementation of attachement because it didn't work. I try several times, So I was wondering where and how I can reference the uploaded file you see in the Html in my "clean" php script who works for sending mail ? Thank's for your reply Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588495 Share on other sites More sharing options...
gw1500se Posted July 22, 2021 Share Posted July 22, 2021 How can we help you if you don't post the errant code? The link I gave you has examples to do what you want. Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588496 Share on other sites More sharing options...
cocolembo Posted July 22, 2021 Author Share Posted July 22, 2021 Ok, Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588497 Share on other sites More sharing options...
maxxd Posted July 22, 2021 Share Posted July 22, 2021 Do yourself a favor and use PHPMailer - it's far easier and more robust than PHP's native mail() function. It also has great debugging output. 1 Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588509 Share on other sites More sharing options...
Strider64 Posted July 23, 2021 Share Posted July 23, 2021 SwiftMailer is also another good one, I use it and it's very simple to use and has good community support: Just a small section of a small script /* create message */ $message = (new Swift_Message('A email from ' . $data['name'])) ->setFrom([$data['email'] => $data['name']]) ->setTo(['example@email.com']) ->setCc([$data['email'] => $data['name']]) ->setBody($data['message'], 'text/html') ->attach(entity: Swift_Attachment::fromPath('https://www.example.com/assets/images/img-logo-003.jpg')); Quote Link to comment https://forums.phpfreaks.com/topic/313415-php-mail-contact-form-file-attachment-not-sending-file/#findComment-1588517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.