Making an autoresponder in php - php

I have a website that has a contact form. And when someone uses it I receive the message. But I would like to set up an autoresponder to inform the person who contacted me that their message has been received etc.
Code:
<?php
$data = json_decode(file_get_contents('admin/data/contact.txt'));
include('includes/header.php');
if(isset($_REQUEST['name'])) {
$to = $settings->email;
$subject = 'Contact from Website';
$headers = "From: " . strip_tags($_REQUEST['email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_REQUEST['email']) . "\r\n";
//$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "Hi, A message from contact form.";
$message .= "<br /><br /><br />Name: ".$_REQUEST['name'];
$message .= "<br />Email: ".$_REQUEST['email'];
$message .= "<br />Subject: ".$_REQUEST['subject'];
$message .= "<br />Message: ".$_REQUEST['message'];
mail($to, $subject, $message, $headers);
$msg = 'Your Message has been sent. Thank You.';
}
$btn = '<input type="submit" style="font-size: 14px; font-style: normal; height: auto; color: #fff; border-radius: 15px; border: none;" class="btn_new" value="SEND" />';
?>
How can I edit this code in order to set this up?
Thank you

....
....
$message .= "<br />Message: ".$_REQUEST['message'];
if(#mail($to, $subject, $message, $headers))
{
echo "Mail Sent Successfully";
//Send autoresponder email to $_REQUEST['email'];
//inform the person who contacted me that their message has been received etc.
}
else
{
echo "Mail Not Sent";
}

Related

PHP email not sending in html format

I am trying to get a PHP email to send in an HTML format, but the current email is just sending in code. I am not sure at all what I am doing wrong.
Does anyone see anything?
ini_set('display_errors', 1);
error_reporting(E_ALL);
$project_name = $_POST['project_name'];
$title_roll = $_POST['title_roll'];
$project_email = $_POST['project_email'];
$project_number = $_POST['project_number'];
$project_description = $_POST['project_description'];
$project_source = $_POST['project_source'];
$project_socialMedia = $_POST['project_socialMedia'];
$project_humanTest = $_POST['project_humanTest'];
$to = 'email';
$subject = 'Project Inquiry Form Sent';
//$message = 'FROM: '.$project_name. "<br>" . ' Email: '.$project_email. "<br>" . 'Message: '.$project_description;
//$msgcontents = "Name: $project_name<br>Email: $project_email<br>Message: $project_description";
$message = '
<html>
<head>
<title>Project Inquiry Form Sent</title>
</head>
<body>
<p>Hi Optimum Designs Team,</p><br>
<p>There has been a Project submitted. Here are the details:</p><br>
<p>Name: '. $project_name .'</p>
<p>Name: '. $title_roll .'</p>
<p>Name: '. $project_email .'</p>
<p>Name: '. $project_number .'</p>
<p>Name: '. $project_description .'</p>
<p>Name: '. $project_source .'</p>
<p>Name: '. $project_socialMedia .'</p><br>
<p>Good Luck,</p>
<p>Administration</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From:' .$project_email . "\r\n";
if (!empty($project_email)) {
if (filter_var($project_email, FILTER_VALIDATE_EMAIL)) {
//Should also do a check on the mail function
if (mail($to, $subject, $message, $headers)) {
echo "Your email was sent!"; // success message
} else {
echo "Mail could not be sent!"; // failed message
}
} else {
//Invalid email
echo "Invalid Email, please provide a valid email address.";
}
} else {
echo "Email Address was not filled out.";
}
That's because your last header
$headers = 'From:' .$project_email . "\r\n";
is missing its concatenate
$headers .= 'From:' .$project_email . "\r\n";
^ right there
in turn breaking the chainlink.

php mail function not working in my server [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I am using PHP mail function to send a mail, But am testing my local sever mail has been sent but my live i cant sent mail. Can you please help me?
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Why use mail() when you have codeigniter email class.
$this->load->library('email');
$this->email->from('your#example.com', 'Your Name');
$this->email->to('someone#example.com');
$this->email->cc('another#another-example.com');
$this->email->bcc('them#their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();
echo $this->email->print_debugger();
Use mandrillapp for sending mail using SMTP, and add credentials for email class.
Try it. It's Working
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'Reply-To: '.$_POST['email'].'' . "\r\n";
$CusHeaders .= 'X-Mailer: PHP/' . phpversion();
$to = "xxxxxxx#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
} else {
echo "Cannot Send Email ";
}
Use this as html(test)
<form action="#" method="post">
<input type="text" name="name" placeholder="name" />
<input type="text" name="email" placeholder="email"/>
<input type="text" name="phone" placeholder="phone" />
<input type="text" name="message" placeholder="message"/>
<input type="submit" name="submit"/>
</form>
PHP
if(isset($_POST[submit]))
{
$email_message = "<b>Form details below</b> <br/><br/>";
$email_message .= "Name: ".$_POST['name']."<br/>";
$email_message .= "Email: ".$_POST['email']."<br/>";
$email_message .= "Phone: ".$_POST['phone']."<br/>";
$email_message .= "Message: ".$_POST['message']."<br/>";
$CusHeaders = 'MIME-Version: 1.0' . "\r\n";
$CusHeaders .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$CusHeaders .= 'From: <'.$_POST['email'].'>' . "\r\n";
$to = "p******#gmail.com";
$subject = "Admin - Our Site! Comment from " ;
if(mail($to,$subject,$email_message,$CusHeaders)) {
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}
}
?>

How do I paste a image on a email message

Oke, this is a tricky one. (I think).
Do you know when you receive a message and the email has a image on top or on the bottom of the page.
I have been trying to make it but can't figure it out.
I hope you guy's can help me with this problem.
This is what I got so far;
<?php
$to = 'info#gmail.com';
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$gast = $_POST['email'];
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if(empty($errors))
{
$to = $to;
$from = $gast;
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
$body = "E-mail".
"Name: $name\n".
"Email: $gast \n".
"Content-Type: {$fileType};\n".
"Content-Transfer-Encoding: base64\n\n".
$data;
$headers = "From: $from \r\n";
$headers .= "Email: $gast \r\n";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= " boundary=\"{$mimeBoundary}\"";
$headers .= "img src='http://cache.estivant.nl/image/1399025430_12_banners-bestemmingen-single-1680x460-extra2-06-kos_1399025430.jpg' alt='image'";
$data = chunk_split(base64_encode($data));
mail($to, $body, $headers);
}
}
?>
<html>
<head></head>
<body>
<form method="post" action="">
<label for="name">name</label>
<input type="name" name="name" value="" />
<label for="email">email</label>
<input type="email" name="email" value="" />
<button id="submit" name="submit">send</button>
</form>
</body>
</html>
Simply write a html page with css styles and format your email accordingly and use the html as your email body. This will create an image in the mail
<img src="image.jpg" alt="image"></img>
Please be aware that most (if not all) email clients will block your image from being showed to your receiver as long as you are not in their trusted sender list or contact list.
Of course, your email has to be sent as html
Here is an example of a nicely formatted email with images.
Note image syntax: <img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />'
$to = 'bob#example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan#example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<img src="http://css-tricks.com/examples/WebsiteChangeRequestForm/images/wcrf-header.png" alt="Website Change Request" />';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Name:</strong> </td><td>" . strip_tags($_POST['req-name']) . "</td></tr>";
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['req-email']) . "</td></tr>";
$message .= "<tr><td><strong>Type of Change:</strong> </td><td>" . strip_tags($_POST['typeOfChange']) . "</td></tr>";
$message .= "<tr><td><strong>Urgency:</strong> </td><td>" . strip_tags($_POST['urgency']) . "</td></tr>";
$message .= "<tr><td><strong>URL To Change (main):</strong> </td><td>" . $_POST['URL-main'] . "</td></tr>";
$addURLS = $_POST['addURLS'];
if (($addURLS) != '') {
$message .= "<tr><td><strong>URL To Change (additional):</strong> </td><td>" . strip_tags($addURLS) . "</td></tr>";
}
$curText = htmlentities($_POST['curText']);
if (($curText) != '') {
$message .= "<tr><td><strong>CURRENT Content:</strong> </td><td>" . $curText . "</td></tr>";
}
$message .= "<tr><td><strong>NEW Content:</strong> </td><td>" . htmlentities($_POST['newText']) . "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";
mail($to,$subject,$message,$headers);
Code source and full explanation: http://css-tricks.com/sending-nice-html-email-with-php/

empty spaces in form and other issues with my contacts page

I'm having some problems with my contact page.
Here are the parts:
<form method="post" action="mail.php">
<input name="nome" type="text" style="width: 265px;" placeholder="Nome e Cognome">
<input name="mail" type="email" style="width: 263px;" placeholder="E-mail">
<textarea name="messaggio" placeholder="Messaggio"></textarea>
<button type="submit" name="invia" style="margin-left: 0; margin-top: 10px;">Invia</button>
</form>
and..
<?php
$to = "mail";
$subject = "Modulo proveniente dal sito www.miosito.it";
$body = "Contenuto del modulo:\n\n";
$body .= "Nome: " . trim(stripslashes($_POST["nome"])) . "\n";
$body .= "Email: " . trim(stripslashes($_POST["mail"])) . "\n";
$body .= "Messaggio: " . trim(stripslashes($_POST["messaggio"])) . "\n";
$headers = "From: Valle srl <info#vallesrl.com>";
"Content-Type: text/html; charset=iso-8859-1\n";
if(#mail($to, $subject, $body, $headers)) {
header("Location: http://www.alessandrogiordano.me/test/valle02/sent.php");
} else {
header("Location: http://www.alessandrogiordano.me/test/valle02/nosent.php");
}
?>
First of all.. if I click on the submit button with all blank the email is sent blank.
Even if I make some errors and I get the else message the email is sent.. blank obviously.
I'm going crazy.. I'm making this website for free for a friend but I'm a graphic designer not a web developer. Never again! :D
Help!! Thank you very much.
put this line in your headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Before sending mail you have to validate all the fields whether they are empty or not
Like this
if( trim($_POST["nome"]) != "" )
{
// send mail
$isMailSend = mail($to, $subject, $body, $headers);
}
{
//show error
}
if( $isMailSend ) {
header("Location: http://www.alessandrogiordano.me/test/valle02/sent.php");
} else {
header("Location: http://www.alessandrogiordano.me/test/valle02/nosent.php");
}
This
$headers = "From: Valle srl <info#vallesrl.com>";
"Content-Type: text/html; charset=iso-8859-1\n";
Should be,
$headers = "From: Valle srl <info#vallesrl.com>";
$headers. = "Content-Type: text/html; charset=iso-8859-1\n";
you can't use type="email",there should be type="text"

SQL Form submit result

I want to display a message something like: "Congrats! you have been registered".
But the message appears on the top left corner of the page. I want to display it in the same page below the "Submit Button".
Here's my code:
if($result)
{
//send the email
$to = "xyz#abc.com";
$subject = "New order for Weaving Hope";
//headers and subject
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
$body = "New contact<br />";
$body .= "Name: ".$name."<br />";
$body .= "Email: ".$email."<br />";
$body .= "Contact No.: ".$contact."<br />";
$body .= "Item Id: ".$itemid."<br />";
$body .= "Quantity: ".$itemquantity."<br />";
$body .= "Comment: ".$comment."<br />";
$body .= "IP: ".$ip."<br />";
mail($to, $subject, $body, $headers);
//ok message
echo "Congrats!";
}
This page should be easy to follow, it tells you exactly what to do.
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/
If you need to do this without AJAX, then you need to process the form data in the same PHP page that sends the form to the browser, and set a flag to determine whether or not the data submission was successful.
For example:
<?php // Call this page register.php
$success = false;
if( $result)
{
// .. Your code from above
$success = true;
}
?>
<form action="register.php" method="post">
<!-- Output the form for submission here -->
<input type="submit" name="register" value="Register" />
<?php if( $success): ?>
<span>Congrats, you are registered!</span>
<?php endif; ?>
</form>

Categories