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.
Related
I am trying to send a message from HTML form. But for some reason I am not getting anything. Could someone please help me ?
Here is my HTML form:
<form method="post" action="subb.php">
<div class="field half first">
<label for="Name">Name</label>
<input type="text" name="Name" id="name" />
</div>
<div class="field half">
<label for="Email">Email</label>
<input type="text" name="Email" id="email" />
</div>
<div class="field">
<label for="Message">Message</label>
<textarea name="Message" id="message" rows="5"></textarea>
</div>
<ul class="actions">
<button type "submit" name="submit" id="submit" class="button submit">Send message</button>
and the PHP:
<?php
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = $_POST['Message'];
$to = "combatstriker111#gmail.com";
$subject="new message";
mail($to , $subject , $Message, "From :" . $Name . $Email);
echo "Your message has been Sent";
?>
I have named the PHP file subb.php and listed them both in the same directories but its still not working for some reason. Any help is very much appreciated.
Something in your code was wrong mail($to , $subject , $Message, "From :" . $Name . $Email);
Mail function SYNTAX :
mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
So,
<?php
if(isset($_POST['submit'])) {
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$Message = "Name : ".$Name."<br />"
$Message .= $_POST['Message'];
$to = "combatstriker111#gmail.com";
$subject="new message";
// 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";
// Additional headers
$headers .= 'To: Name <$to>' . "\r\n";
$headers .= 'From: $Name <$Email>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
if(mail($to, $subject, $Message, $headers)) {
echo "Your message has been Sent";
} else {
echo "Mesage Error";
}
}
?>
Note : Use any mail library for prevent vulnerable to header injection like PHPMailer
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];;
$subject = $_POST['subject'];
$message = $_POST['message'];
$to = 'info#fullertoncomputerepairwebdesign.com';
$subject = 'Message From Website';
$headers = 'From: info#fullertoncomputerepairwebdesign.com' . "\r\n" .
'Reply-To: info#fullertoncomputerepairwebdesign.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$themessage = "Name: ".$name."</br>Email: ".$email."</br>Phone: ".
$phone."</br>Subject: ".$subject.
"</br>Message: ".$message;
//echo $themessage;
if(mail($to, $subject, $themessage, $headers)){
echo "message sent";
header( 'Location: http://www.fullertoncomputerepairwebdesign.com/contactus.php?smresponse=Message Sent' ) ;
}else{
echo "we have a error charlie!";
}
;
test this out and if it doesn't work it means your hosting blocks mail function.
I have my form setup and working perfect, however I need to add attachment functionality (only) to this. I've reviewed several threads and tried implementing but with no luck.
I'm trying to add id='file-7'
HTML code:
<fieldset class="clean">
<textarea name="comments" id="comments" placeholder="Message*"></textarea>
</fieldset>
<fieldset class="percent-one-full">
<div class="box">
<input type="file" name="file-7[]" id="file-7" class="inputfile inputfile-6" data-multiple-caption="{count} files selected" multiple />
<label for="file-7"><span></span> <strong><svg xmlns="http://www.w3.org/2000/svg" width="20" height="17" viewBox="0 0 20 17"><path d="M10 0l-5.2 4.9h3.3v5.1h3.8v-5.1h3.3l-5.2-4.9zm9.3 11.5l-3.2-2.1h-2l3.4 2.6h-3.5c-.1 0-.2.1-.2.1l-.8 2.3h-6l-.8-2.2c-.1-.1-.1-.2-.2-.2h-3.6l3.4-2.6h-2l-3.2 2.1c-.4.3-.7 1-.6 1.5l.6 3.1c.1.5.7.9 1.2.9h16.3c.6 0 1.1-.4 1.3-.9l.6-3.1c.1-.5-.2-1.2-.7-1.5z"/></svg> Upload fileā¦</strong></label>
<input name="send" type="submit" class="button red" id="submit" onClick="MM_validateForm('name','','R','bandname','','R', 'email','','RisEmail','comments','','R');return document.MM_returnValue" value="SEND"/>
JS code:
jQuery(document).ready(function(){
$('#cform').submit(function(){
var action = $(this).attr('action');
$("#message").slideUp(750,function() {
$('#message').hide();
$('#submit')
.after('<img src="images/nivo-preloader.gif" class="contact-loader" />')
.attr('disabled','disabled');
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
bandname: $('#bandname').val(),
osflow: $('#osflow').val(),
hiddenDiv: $('#hiddenDiv').val(),
hiddenDivv: $('#hiddenDivv').val(),
hiddenDivvv: $('#hiddenDivvv').val(),
hiddenDivvvv: $('#hiddenDivvvv').val(),
hiddenDivvvvv: $('#hiddenDivvvvv').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data){
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#cform img.contact-loader').fadeOut('slow',function(){$(this).remove()});
$('#submit').removeAttr('disabled');
if(data.match('success') != null) $('#cform').slideUp('slow');
}
);
});
return false;
});
});
PHP code:
<?php
if(!$_POST) exit;
// Email address verification, do not edit.
function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+#((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "\r\n");
print_r($_POST);
$name = $_POST['name'];
$email = $_POST['email'];
$_POST['bandname'];
$_POST['osflow'];
$_POST['hiddenDiv'];
$_POST['hiddenDivv'];
$_POST['hiddenDivvv'];
$_POST['hiddenDivvvv'];
$_POST['hiddenDivvvvv'];
$comments = $_POST['comments'];
//$verify = $_POST['verify'];
if(trim($name) == '') {
echo '<div class="error_message">Attention! You must enter your name.</div>';
exit();
} else if(trim($email) == '') {
echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
exit();
} else if(!isEmail($email)) {
echo '<div class="error_message">Attention! You have enter an invalid e-mail address, try again.</div>';
exit();
}
if(trim($comments) == '') {
echo '<div class="error_message">Please enter your message.</div>';
exit();
//} else if(!isset($verify) || trim($verify) == '') {
// echo '<div class="error_message">Please enter the verification number. </div>';
// exit();
//} else if(trim($verify) != '4') {
// echo '<div class="error_message">The verification number you entered is incorrect.</div>';
// exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "joe.doe#yourdomain.com";
//$address = "example#example.net";
$address = "info#example.com";
// Configuration option.
// i.e. The standard subject will appear as, "You've been contacted by John Doe."
// Example, $e_subject = '$name . ' has contacted you via Your Website.';
$e_subject = 'Decal Inquiry from ' . $name . '';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name. The additional message is as follows." . PHP_EOL . PHP_EOL;
$e_body = "Name: $name" . PHP_EOL . "\r\n";
$e_body2 = "Email: $email" . PHP_EOL . "\r\n";
$e_custom = "Band Name: $bandname" . PHP_EOL . "\r\n";
$e_custom2 = "Interest In: $osflow" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Size: $hiddenDiv" . PHP_EOL . "\r\n";
$e_custom3 = "Drum Head Color: $hiddenDivv" . PHP_EOL . "\r\n";
$e_custom4 = "Mic Port Position: $hiddenDivvv" . PHP_EOL . "\r\n";
$e_custom5 = "Banner Color: $hiddenDivvvv" . PHP_EOL . "\r\n";
$e_custom6 = "Banner Size: $hiddenDivvvvv" . PHP_EOL . "\r\n";
$e_content .="Content-Disposition: attachment; filename=$file-7" . "\r\n";
$e_content = "Comments: $comments" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email at $email.";
$msg = wordwrap( $e_body . $e_body2 . $e_custom . $e_custom2 . $e_custom3 . $e_custom4 . $e_custom5 . $e_custom6 . $e_custom7 . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div id='success_page'>";
echo "<h1>Email Sent Successfully.</h1>";
echo "<p>Thank you <strong>$name</strong>, we've received your inquiry and will be in touch shortly.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo 'ERROR!';
}
Any help would be much appreciated!
I am not good at PHP but still trying to create a test script so that i can learn it. I am referring to w3schools and i don't know how good or bad i am.
I need some changes to be made to what script i just created.
<?php
$to = $_POST['EmailList'];
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
mail($to,$subject,$message,$headers);
print_r($headers)
?>
<html>
<center>
<form method="post">
<br><strong>PHP Email Sender</strong><br><br><br>
Email List<br>
<textarea name="EmailList" placeholder="email#email.com (New Email Each Line)" rows="20" cols="50"></textarea><br><br>
Subject<br>
<input type="text" name="EmailSubject" placeholder="Your Subject Goes Here"><br><br>
Body<br>
<textarea name="EmailBody" placeholder="Write your content (HTML Accepted)" rows="20" cols="50"></textarea><br><br>
<input type="submit" value="Submit!">
</form><br><br>
</center>
</html>
I want some help so that i can send email's to different email's but each email would be in a different line and i would not be using a comma(,). I want the script to generate the comma(,) by its own and carry each email from a new line.
For example i entered 10 emails i need each email to be printed and a message saying sent besides that.
Please let me know if this is possible. I just need some help.
This is tested:
<?php
$subject = $_POST['EmailSubject'];
$message = $_POST['EmailBody'];
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <admin#admin.com>' . "\r\n";
$emailList = explode("\n",$_POST['EmailList']);
if(count($emailList) > 0){
foreach($emailList as $to){
$to = trim($to);
$sent = mail($to,$subject,$message,$headers);
if ($sent){
echo "<p>Sent: $to</p>";
}
else{
echo "<p>Not Sent: $to</p>";
}
}
}
else{
echo "<p>No email addresses</p>";
}
print_r($headers);
?>
How can I run this contact form without reloading or changing the page on submit? I was told to use ajax but I don't know where to start with that.
I would like to be able to display the output ('Successfully sent! Thank you.') on my index.html inside a div for example.
<?php if (isset($_POST["contact"])){
$to = 'contact#example.com'; //Contact Email
$from = $_POST["email"];
$name = $_POST["name"];
$message = $_POST["message"];
// subject
$subject = 'New message from '.$name;
// 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";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: '.$from . "\r\n";
// Mail it
if(mail($to, $subject, $message, $headers)){
echo "Successfully sent! Thank you.";
} else {
echo "Oops! Failed to send your message";
}
}
?>
Try the below codes =)
html
<form id="contactform" name="contactform" method="post" action="email.php">
<div>
<input type="text" name="name">
</div>
<div>
<input type="email" name="email">
</div>
<div>
<input type="text" name="subject">
</div>
<div>
<textarea name="message"></textarea>
</div>
<button type="submit">
Send Message
</button>
</form>
ajax
var form = $('#contactform');
form.submit(function(event){
event.preventDefault();
var form_status = $('<div></div>');
$.ajax({
type:"post",
url: $(this).attr('action'),
data: $(this).serialize(),
beforeSend: function(){
form.prepend( form_status.html('<p>Sending</p>').fadeIn() );
}
}).done(function(data){
form_status.html('<p>Done</p>').delay(3000).fadeOut();
});
});
email.php
<?php
$to = 'contact#example.com'; //Contact Email
$from = $_POST["email"];
$name = $_POST["name"];
$message = $_POST["message"];
// subject
$subject = 'New message from '.$name;
// 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";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: '.$from . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
echo '<div id="email">
<form action="#" method="POST">
<label>E-mailadres:</label>
<p><input type="text" name="mail1" value="me#me.nl"> </p>
<input type="submit" name="submitemail">
</form>
</div>';
$to = 'MY#MAIL.COM';
$lala = $_POST['mail1'];
// subject
$subject = 'Subject';
// message
$message = $selected . $totaal .'';
// 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: ' . $lala . ' <' . $lala . '>';
// Mail it
mail($to, $subject, $message, $headers);
Sending the email is working fine, it just wont let catch the inserted email.
I can't get the value of <input .... name="mail1"> (me#me.nl) into the "FROM:" section.
What do i wrong OR what is the thing that i don't do in this case ?
Whenever using $headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n"; it works perfectly.
Try
echo '<div id="email">
<form action="a.php" method="POST">
<label>E-mailadres:</label>
<p><input type="text" name="mail1" value="me#me.nl"> </p>
<input type="submit" name="submitemail">
</form>
</div>';
if (isset($_POST['submitemail'])) {
$to = 'MY#MAIL.COM';
$lala = $_POST['mail1'];
// subject
$subject = 'Subject';
// message
$message = $selected . $totaal . '';
// 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: ' . $lala . ' <' . $lala . '>';
// Mail it
mail($to, $subject, $message, $headers);
}
the a.php is the name of ur php file