Sending an email using a php contact form - php

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

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 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.

php html contact form with arabic message

I'm working on contact form for my site, everything work good if i fill the inputs in English language but if i fill the inputs in arabic language i don't receive any emails, how i can fix this ?
this is my code :
HTML code :
<section class="body">
<form action="form.php" method="post" enctype="multipart/form-data">
<h1 class="title">Contact</h1>
<label></label>
<input name="d_name" required="required" placeholder="أسم المندوب">
<label></label>
<input name="d_phone" type="text" required="required" placeholder="رقم هاتف المندوب">
<label></label>
<input name="c_name" type="text" required="required" placeholder="أسم المشترك">
<label></label>
<input name="phonee" required="required" type="text" placeholder="رقم هاتف المشترك" />
<label></label>
<select class="dropdown-select" name="comp" required="">
<option disabled="disabled" selected="selected" value="">أختر الشركة</option>
<option value="جولان">جولان</option>
<option value="بارتنير">بارتنير</option>
<option value="بلفون">بلفون</option>
<option value="تيلزار 019">تيلزار 019</option>
</select>
<label></label>
<select name="type" required="">
<option disabled="disabled" selected="selected" value="">اختر نوع الرقم</option>
<option value="فاتورة">فاتورة</option>
<option value="كرت">كرت</option>
</select>
<label></label>
<input name="sim" required="required" type="text" placeholder="رقم الشريحة" />
<label></label>
<textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<input id="cancel" name="cancel" value="Cancel" />
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
PHP code :
<?php
$name = $_POST['d_name'];
$phone = $_POST['d_phone'];
$cname = $_POST['c_name'];
$cphone = $_POST['phonee'];
$comp = $_POST['comp'];
$sim = $_POST['sim'];
$type = $_POST['type'];
$message = $_POST['message'];
$from = 'From:' . $_POST['d_name'];
$to = 'Noor_Phone#hotmail.com';
$subject = 'Email Inquiry';
$body = "Delegate Name: $name\n Delegate phone: $phone\n\n\n Customer Name: $cname\n Customer Phone: $cphone\n Line Type: $type\n Company: $comp\n Sim Number: $sim\n Message:\n $message";
?>
<?php
if ($_POST['submit']) {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Thank you for your email!</p>';
} else {
echo '<p>Oops! An error occurred. Try sending your message again. </p>';
}
}
?>
Instead of using php built-in mail function, use phpmailer. This will solve your problem. Using this class you have the option to set charset:
$mail->CharSet = 'UTF-8';
For additional troubleshooting, you can
<meta charset="utf-8">
You also have the option to include charset attribute in the form tag:
<form action="form.php" method="post"
enctype="multipart/form-data" accept-charset="utf-8">
Or have a look at this old SO answer on sending arabic content in email.
Hope this may help.
Setting the Html Lang might help this situation try this
<html lang="ar">
Referenced from http://www.w3schools.com/tags/ref_language_codes.asp
thanks for helping ,this is the answer:
HTML Code:
<h1 class="title">Contact</h1>
<label></label>
<input name="d_name" required="required" placeholder="أسم المندوب">
<label></label>
<input name="d_phone" type="text" required="required" placeholder="رقم هاتف المندوب">
<label></label>
<input name="c_name" type="text" required="required" placeholder="أسم المشترك">
<label></label>
<input name="phonee" required="required" type="text" placeholder="رقم هاتف المشترك" />
<label></label>
<select class="dropdown-select" name="comp" required="">
<option disabled="disabled" selected="selected" value="">أختر الشركة</option>
<option value="جولان">جولان</option>
<option value="بارتنير">بارتنير</option>
<option value="بلفون">بلفون</option>
<option value="تيلزار 019">تيلزار 019</option>
</select>
<label></label>
<select name="type" required="">
<option disabled="disabled" selected="selected" value="">اختر نوع الرقم</option>
<option value="فاتورة">فاتورة</option>
<option value="كرت">كرت</option>
</select>
<label></label>
<input name="sim" required="required" type="text" placeholder="رقم الشريحة" />
<label></label>
<textarea name="message" cols="20" rows="5" required="required" placeholder="Message"></textarea>
<input id="cancel" name="cancel" value="Cancel" />
<input id="submit" name="submit" type="submit" value="Submit">
</form>
</section>
PHP Code:
<?php
$mail->CharSet = 'UTF-8';
$name = $_POST['d_name'];
$phone = $_POST['d_phone'];
$cname = $_POST['c_name'];
$cphone = $_POST['phonee'];
$comp = $_POST['comp'];
$sim = $_POST['sim'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent="Delegate Name: $name\n Delegate phone: $phone\n\n\n Customer Name: $cname\n Customer Phone: $cphone\n Line Type: $type\n Company: $comp\n Sim Number: $sim\n Message:\n $message";
$recipient = "Noor_Phone#hotmail.com";
$subject = "Contact Form";
$mailheader = "From: admin#4uphone.co.il";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='contact.html' style='text- decoration:none;color:#ff0099;'> Return Home</a>";
?>

how to send and make a php email form

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.

Categories