Jump to content

php Mail Contact Form - File Attachment - Not sending file


cocolembo
 Share

Recommended Posts

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 by cocolembo
Link to comment
Share on other sites

  • cocolembo changed the title to php Mail Contact Form - File Attachment - Not sending file
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

Link to comment
Share on other sites

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'));

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.