I am trying to have a php mailer code attach a file along with the regular information. I don't know what to do. Here is how far I have come.
Form.html
<form method="post" name="contact" action="contactprocessor.php">
<label for="name">Name: </label> <input type="text" id="name">
<label for="email">email: </label> <input type="email" id="email">
<label for="file">Upload file: </label> <input type="file" id="file">
<input type="submit" id="name" value="upload">
contactprocessor.php
<?php
$emailSubject = 'file upload';
$mailto ='me#mymail.com';
$nameField = $_POST['name'];
$emailField = $_POST['email'];
$body = <<<EOD
NAME: $name <br>
Email: $email <br>
EOD;
$headers = "from: $email\r\n";
$success = mail($mailto, $emailSubject, $body, $headers);
?>
Unfortunately, you can't send file with email directly. I recommend to use phpmailer class (http://code.google.com/a/apache-extras.org/p/phpmailer/) but also there is a traditional way: http://webcheatsheet.com/php/send_email_text_html_attachment.php
first off you need to add enctype="multipart/form-data" to your
they're right, there are tutorials to do such a thing. They usually involve multiparts and base64
Related
This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 4 years ago.
I am fairly new to coding and am having an issue with my website contact form. It won't allow me to receive email when the form is filled and submit button clicked.
I know nothing about PHP and it's obvious something is missing or incorrect. I've included only the relevant portions of the file...thanks for any help I can get!
<div id="page_4">
<div id="wrapper">
<form action="contact form.php" method="post">
<label for="fname">Name</label>
<input type="text" name="name" placeholder="Full name...">
<label for="email">Email</label>
<input type="text" name="email" placeholder="...">
<label for="phone">Phone</label>
<input type="text" name="phone" placeholder="...">
<label for="subject">Subject</label>
<input type="text" name="subject" placeholder="...">
<label for="detail">Project Detail</label>
<textarea name="detail" placeholder="Please use detail if possible..." style="height:200px"></textarea>
<label for="deadline">Project Deadline (MO/DY/YR)</label>
<input type="text" name="deadline" placeholder="...">
<input type="submit" value="Submit">
</form>
</div>
</div>
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$subject = $_POST['subject'];
$mailfrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "mark#markabove.com";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name."\n\n".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.html?mailsend");
}
?>
The URL for the form action tag has a space in it. Perhaps change it to contact-form.php.
So I have created a form inside html the code -
<form method="post" action="hi.php">
<fieldset>
<label class="labelone" type="text" />
<input name="name" placeholder="Your Name"/>
<label class="email" for="email" />
<input name="email" placeholder="Email"/>
<label class="phonenumber" for="phonenumber" />
<input name="phonenumber" placeholder="Phone Number"/>
<label class="comments" for="comments" />
<textarea name="comments" placeholder="Comments"></textarea>
</fieldset>
<fieldset>
<input type="submit" value="Submit" class="btn" >
<input class="btn" type="reset" value="Reset">
</fieldset>
</form>
and this is the php -
<?php
$emailSubject = 'Test';
$webMaster = 'Test';
$name = $_GET['firstname'];
$email = $_GET['lastname'];
$message = $_GET['comment'];
$body = <<<EOD
<br><hr><br>
First Name: $firstname <br>
Last Name: $lastname <br>
Message: $comment <br>
EOD;
$headers = "From: $lastname\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
<?php
?>
<?php
$emailSubject = 'Kent Pest Control Services';
$webMaster = 'xxxxxxxxxEDITED#gmail.com';
$name = $_GET['firstname'];
$email = $_GET['email'];
$phonenumber = $_GET['phonenumber']
$message = $_GET['comments'];
$body = <<<EOD
<br><hr><br>
First Name: $firstname <br>
Email: $email <br>
Phone Number: $phonenumber <br>
Message: $comments <br>
EOD;
When I upload it to my hosting and fill in the php form, and click submit, it goes to a blank screen, and I dont get an email, I have used this before like a year ago, I dont know if the code has changed since then, but I cant get it to work, I hope someone can help. :) I changed the email so people cant email me ;)
you are missing a <form> tag in your HTML.
try this:
<form action="yourPHPfile.php" method="post">
<fieldset>
<label class="labelone" type="text" />
<input name="name" placeholder="Your Name"/>
<label class="email" for="email" />
<input name="email" placeholder="Email"/>
<label class="phonenumber" for="phonenumber" />
<input name="phonenumber" placeholder="Phone Number"/>
<label class="comments" for="comments" />
<textarea name="comments" placeholder="Comments"></textarea>
</fieldset>
<fieldset>
<input type="submit" value="Submit" class="btn" >
<input class="btn" type="reset" value="Reset">
</fieldset>
</form>
I would use POST, and not GET as you are passing potentially a lot of data through and it would create a very ugly url.
your php file then..
<?php
$emailSubject = 'Test';
$webMaster = 'Test';
$name = $_POST['firstname'];
$email = $_POST['lastname'];
$message = $_POST['comments']; // you have the wrong key in your original file (comment)
$body = <<<EOD
<br><hr><br>
First Name: $firstname <br>
Last Name: $lastname <br>
Message: $comment <br>
EOD;
$headers = "From: $lastname\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
?>
other points:
you should be validating the email address server side if youre going to do anything else with it, like send back a confirmation etc
I think this code can resolve you query
<form action="actionname.php" method="post">
<fieldset>
<label class="labelone" type="text" />
<input name="firstname" placeholder="Your firstName"/>
<label class="labeltwo" type="text" />
<input name="lastname" placeholder="Your LastName"/>
<label class="email" for="email" />
<input name="email" placeholder="Email"/>
<label class="phonenumber" for="phonenumber" />
<input name="phonenumber" placeholder="Phone Number"/>
<label class="comments" for="comments" />
<textarea name="comments" placeholder="Comments"></textarea>
</fieldset>
<fieldset>
<input type="submit" value="Submit" class="btn" >
<input class="btn" type="reset" value="Reset">
</fieldset>
</form>
Now this php code
<?php
$emailSubject = 'Test';
$webMaster = $_POST['email']; /* Pass your form email address here */
$firstname = $_POST['firstname']; /* Firstname from form */
$lastname = $_POST['lastname']; /* Lastname from form */
$message = $_POST['comments']; /* Comment from form */
$body = <<<EOD
<br><hr><br>
First Name: $firstname <br>
Last Name: $lastname <br>
Message: $message <br>
EOD;
$headers = "From: $lastname\r\n";
$headers = "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$theResults = <<<EOD
?>
can anybody help me fix my php code so that it will send the form data to the email address? i am using MAMP Server to check wether it works the website works as planned however once i fill the form out and press submit it takes me to the PHP page however no email is sent.
PHP CODE
<?php
if(isset($_POST['submit'])){
$emailSubject = 'Customer Has a Question!';
$webMaster = 'r1bos#hotmail.com';
$nameField = $_POST ['Full_Name'];
$emailField = $_POST['E-Mail'];
$phoneNumber = $_POST['Phone_Number'];
$questionField = $_POST ['Query'];
$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Questions: $question <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
#mail($webMaster, $emailSubject, $body, $headers);
exit;
}
?>
HTML FORM
<form action="Php/form.php" method="post" name="Contact_Form" >
<label for="fullname">Full Name: </label>
<input type="text" name="Full_Name" id="name"><br>
<label for="E-Mail">E-Mail: </label>
<input type="text" name="E-Mail" id="email" ><br>
<label for="PhoneNumber">Phone Number: </label>
<input type="text" name="Phone_Number" id="phonenumber" ><br>
<label for="Query">Query: </label>
<textarea name="Query" rows="4" cols="21" id="query" ></textarea><br>
<input type="submit" name="submit" value="Send" >
</form>
How to connect my email attachtment form to php. direct my email.
Html :-
<form id="form" class="blocks" enctype="multipart/form-data" action="js/upload_file.php" method="post">
<p>
<label>
Name:</label>
<input type="text" class="text" name="name" />
</p>
<p>
<label>
Address:</label>
<input type="text" class="text" name="address" />
</p>
<p>
<label>
Phone:</label>
<input type="text" class="text" name="phone" />
</p>
<p class="area">
<label>
Year Exp:</label>
<input type="text" class="text" name="exp" />
</p>
<p class="area">
<label for="file">
Upload ur CV:</label>
<input type="file" name="attachment">
</p>
<p>
<label>
</label>
<input type="submit" class="btn" value="Submit" />
</p>
</form>
<div class="right">
<img src="images/Careers.png" width="350" height="334">
</div>
</div>
</div>
</div>
How to connect my email attachtment form to php. direct my email.
How to connect my email attachtment form to php. direct my email.
How to connect my email attachtment form to php. direct my email.
PHP :-
<?php
if (isset($_REQUEST['email']))
{
$domain='www.example.com';
$from='www.example.com';
$name = $_REQUEST['name1'] ;
$add = $_REQUEST['add'] ;
$phone = $_REQUEST['phone'] ;
$exp = $_REQUEST['exp'] ;
$attachment = $_REQUEST['attachment'] ;
$subject = 'Massage recieved from Pearl : '.$domain.'';
$body = $email.'
The person that contacted you is : '.$name.'
|------------------Full Details--------------------|
Name: '.$name.'
Address: '.$add.'
Phone: '.$phone.'
Experience: '.$exp.'
Attachment: '.$attachment.'
|--------------------End---------------------------|';
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Thank you for your feedback. We will contact you shortly')
window.location.href='http://www.pearlgroup.asia';
</SCRIPT>");
mail("info#example.com",$from, $subject, $body);
// Check, if message sent to your email
// display message "We've recived your information"
}
else
{
echo "Try again";
}
?>`
If I understood your question: http://webcheatsheet.com/PHP/send_email_text_html_attachment.php
Hope it helps.
Based on this articles (http://www.html-form-guide.com/email-form/php-email-form-attachment.html) that use pear library, after you get the attachment and processing it, then then you can send the email use Mail library ...
$message = new Mail_mime();
$message->setTXTBody($text);
$message->addAttachment($path_of_uploaded_file);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$visitor_email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
If you want to use swift (http://swiftmailer.org/), the logic still the same ...
$message = Swift_Message::newInstance('Subjct', 'Body message');
$message->attach(Swift_Attachment::fromPath('/path/to/file'));
i have a contact form with out file attachment(its working properly) .How i can convert this contact form into file attachment.Can you also tell me how this file attachment script works.I tried web but there is no clear answer for this problem.this is my script
<form action="" enctype="multipart/form-data" method="post">
<label for="name">Name:</label><br/>
<input type="text" id="name" name="name" /><br/>
<label for="email">Email address:</label><br/>
<input type="text" id="email" name="email" /><br/>
<label for="topic">Subject:</label><br/>
<input type="text" id="topic" name="topic" /><br/>
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<label>Upload a Menu:</label>
<input type="file" name="file" size="20"><br>
<label for="comments">Your comments:</label><br/>
<textarea id="comments" name="comments" rows="5" cols="30"></textarea><br/>
<button name="submit" type="submit">Send</button>
</form>
<?php
if(isset($_POST['submit']))
{
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'example#gmail.com';
$subject = "Contact: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
echo('<br> your mail has been send<br>');
}
?>
The uploaded file is saved to a temporary location. You can then copy the file from there to wherever you want to use or permanently save it. All of the file information is actually in the $_FILES superglobal instead of $_POST.
In your case, the path where the file is temporarily saved can be found in $_FILES['file']['tmp_name'].
See the manual here, where it explains how this works with examples.
Attaching the file to an email, however, is another beast. You'd be best served to use a PHP mailer class for this rather than just using mail() yourself. Look at PHPMailer, for example.