how to send and make a php email form - php

Ok I try to get this every time but I can't I'm using xampp and thunderbird, so I tryed to make a email form so people can contact me but i have the code right but it won't send to my gmail what am I doing wrong. and need to make a activation php too so they can sign up for my website.
<form action="test1.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
thats form.html and my php is test1.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "dstokesncstudio#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text- decoration:none;color:#ff0099;'> Return Home</a>";
?>

Are you hosting on a Linux or other Unix-like systems? If so, depending on where the server(s) where the page is hosted, you need to ensure that sendmail or postfix is actually running.
As root you can run 'mailq' (see man pages) to see if the message is being queued up but there is no daemon running that is processing it.
Also double-check your spam folder to see if it is getting tagged as such by gmail.

Related

PHP mail script not redirecting or sending emails

I'm using the following php script on a contact form but it is neither sending emails or redirecting -
<?php
if (isset($_POST['submit'])) {
$jobtype = $_POST['jobtype'];
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mailto = "myemail";
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n $jobtype \n Name: $name \n ".
"Email: $email \n Message \n $message";
mail($mailto, $email_subject, $email_body,);
header("Location: thank-you.html?mailsend");
}
?>
The contact form is as follows -
<form action="/contact.php" method="POST">
<label for="jobtype">What can I do for you?</label>
<select id="jobtype" name="jobtype">
<option value="web-design">Web Design</option>
<option value="logo-design">Logo Design</option>
<option value="graphic-design">Graphic Design</option>
<option value="photo-video">Photography/Video</option>
<option value="general-enquiry">General Enquiry</option>
</select>
<label for="name">Who are you?</label>
<input type="text" id="name" name="name" placeholder="Your name is..">
<label for="email">Your email?</label>
<input type="text" id="email" name="email" placeholder="Your email is..">
<label for="message">A quick description of the job</label>
<textarea id="message" name="message" placeholder="Let me know here.." style="height:200px"></textarea>
<input type="submit" value="Submit">
</form>
I've tried some of the fixes on here but none seem to work, any help is appreciated!

Form Multiselect option is only returning 1 option in message

this is my first time making a form, and I have multi-select option but I think I'm missing out something because the form is working but when selecting multiple options the email I receive is only showing 1 option.
<form action="send.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Services</p>
<select data-placeholder="Responsible For...." multiple class="chosen-select full_width" name="service" tabindex="-1">
<option value="Medical">Medical</option>
<option value="Finance">Finance</option>
<option value="Construction">Construction</option>
<option value="IT Services">IT Services</option>
</select>
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
send.php
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$service = $_POST['service'];
$message = $_POST['message'];
$formcontent=" From: $name \n Type: $service \n Message: $message";
$recipient = "itssonu4564#gmail.com";
$subject = "Message";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
You need to do a small change in your HTML. Add a bracket pair to the name attribute, to make PHP it recognize it as an array.
<select multiple name="service[]">
Afterwards in PHP you can use
$service = implode(', ', $_POST['service']);
To get all services as a comma separated list.
The name of select option should be array[] type
name="service[]"

Contact submit button redirects to blank .PHP url?

I have a contact form that I would like to send to my email address at my domain. However, upon hitting the "Submit" button, the website gets redirected to the .PHP url where it gives me:
HTTP ERROR 500: This page isn’t working "mywebsite.com" is currently unable to handle this request.
No email is received and the header("Location: ") doesn't redirect. I am currently using Bluehost. You can find the form I'm working on at acromojo.com/contact. I haven't added security yet, just trying to get the form to work first.
What am I doing wrong?
HTML:
<form method="post" action="contactform.php">
<div><select name="projectType">
<option value="0">Start A Project</option>
<option value="1">General Inquiry</option>
<option value="2">Collaborating</option>
</select></div></br>
<input name="name" type="text" placeholder="Full Name" required>
<input name="company" type="text" placeholder="Company / Organization"></br>
<input name="phone" type="phone" placeholder="Phone Number" required>
<input name="email" type="email" placeholder="Email Address"></br>
<input name="location" type="text" placeholder="Location">
<select name="find">
<option value="0">How did you hear about us?</option>
<option value="1">Social Media</option>
<option value="2">Search Engine</option>
<option value="3">Referrals / Recommendations</option>
<option value="4">Other</option>
</select></br></br>
<textarea name="message" placeholder="Please tell us a little about your project, timeline, and budget" row="4" required></textarea></br>
<label>Sign me up for the latest news, events, and more
<input name="newsletter" type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<input type="submit" name="submit" value="SUBMIT">
</form>
PHP:
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$subject = $_POST['projectType'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$location = $_POST['location'];
$find = $_POST['find'];
$message = $_POST['message'];
$newsletter = $_POST['newsletter'];
$headers = "From: $email";
$txt = "You have received an e-mail from ".$name."\n\n"
"Location: ".$location."\n"
"Contact: ".$phone.", ".$email."\n"
"Found from: ".$find."\n\n"
.$message;
mail("hello#acromojo.com", $subject, $txt, $headers);
header("Location: contact.html?mailsent");
}
The answer came to me after aaaaaa123456789 commented. I checked the error_log where it was returning:
PHP Parse error: syntax error, unexpected '"Location: "' (T_CONSTANT_ENCAPSED_STRING)
Fix: "\r\n""Location: "
To: "\r\n Location: "

Contact form not sending mail

I have this contact form and the PHP for it but it wont send the emails at all, can i get a second set of eyes on this please? the first code sample below is from the index.html and PHP is from contact.php
Contact form:
<form action="contact.php" method="POST">
<p>Name</p> <input type="text" name="name" class="form-control">
<p>Email</p> <input type="text" name="email" class="form-control">
<p>Phone</p> <input type="text" name="phone" class="form-control">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call" class="form-control">
No:<input type="checkbox" value="No" name="call" class="form-control">
<p>Priority</p>
<select name="priority" size="1" class="form-control">
<option value="Low" class="form-control">Low</option>
<option value="Normal" class="form-control">Normal</option>
<option value="High" class="form-control">High</option>
<option value="Emergency" class="form-control">Emergency</option>
</select>
<p>Message</p><textarea name="message" rows="6" cols="25" class="form-control"></textarea><br />
<input type="submit" value="Send"class="form-control"><input type="reset" value="Clear" class="form-control">
Contact.php-
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Priority: $priority \n Message: $message";
$recipient = "test#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>
mail(to,subject,message,headers,parameters);
But in case of your code to email id is fixed : test#gmail.com
change $recipient with $email.

Sending an email using a php contact form

i am trying to create a contact form using php. When i click send the email appears to have sent but the recipient never actually receives it. Maybe i need to set up an SMTP server but i am unsure how to do this. Thanks in advance
in the form.html i have
<form action="mail.php" method="POST">
<p>Name</p> <input type="text" name="name">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Request Phone Call:</p>
Yes:<input type="checkbox" value="Yes" name="call"><br />
No:<input type="checkbox" value="No" name="call"><br />
<p>Website</p> <input type="text" name="website">
<p>Priority</p>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<p>Type</p>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<p>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
in the mail.php file i have
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$call = $_POST['call'];
$website = $_POST['website'];
$priority = $_POST['priority'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n Phone: $phone \n Call Back: $call \n Website: $website \n Priority: $priority \n Type: $type \n Message: $message";
$recipient = "kerrip90#hotmail.co.uk";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text- decoration:none;color:#ff0099;'> Return Home</a>";
?>
For the mail() function to work you can simply just install postfix on your server by issuing this command:
sudo apt-get install postfix
You can try the pear package.
sudo apt-get install pear
sudo pear install mail
The installation will recommend few other packages too.Install them in the same way.To send the mail use:
public function sendMail($to)
{
require_once('Mail.php');
$this->_to=$to;
$host = "ssl://smtp.gmail.com";
$port = "465";
$headers = array ('From' => $this->_from,
'To' => $this->_to,
'Subject' => $this->_subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $this->_username,
'password' => $this->_password));
$mail = $smtp->send($this->_to, $headers, $this->_body);
}

Categories