Im trying to get my php mailer embedded on my html page, I get no syntax errors in Dreamweaver but sendmail (http://glob.com.au/sendmail/) keeps giving me this error message "Syntax error in arguments
" Im hoping you can help me nail the issue
My PHP mailer:
//Email information
$admin_email = "------------ Secret";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
Here is the relevant page code
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "schlichtingr#yahoo.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
//send email
mail($admin_email, "$subject", $comment, "From:" . $email);
//Email response
echo "Thank you for contacting us!";
}
//if "email" variable is not filled out, display the form
else {
?>
<html>
<head>
</head>
<body>
<div id ="Email">
<form method="post"><br />
<h3><b>send us a message</b></h3>
<span>Any further questions or concerns? Send us an email!</span><br>
Email: <input name="email" type="text" /><br />
Subject: <input name="subject" type="text" /><br />
Message:<br />
<textarea name="comment" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" />
</form>
</div>
<?php
}
?>
Any help you can give me would be much appreciated
I am new to php but still trying to learn
Basically I just want to make a mail form built onto an html page
I'm not familiar with sendmail, but I notice 1 thing:
"$subject" needs to be just $subject . You are capturing that variable for a reason. So turning it into a string of "$subject" makes no sense to me.
Hope this helps!
Try this code:
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "user#example.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$comment = $_REQUEST['comment'];
$headers = "From: $email" . "\r\n";
mail($admin_email, $subject, $comment, $headers);
//Email response
echo "Thank you for contacting us!";
}
Related
This is my first time trying to create a php forum. Let's say I have a first user that posts a subject and enters his email address.
<form action="whatever.php" method="post">
Discussion Content:
<br />
<input type="text" name="name" style="height:200px; width:800px" />
<br />
E-mail:
<input type="text" name="poster#emai.com" />
<br />
<input type="submit" />
</form>
Then I need the second user to be able to respond to the first user's post and second user's reply to be sent directly to first user's email. So this is what I've got and it's not even close. Appreciate any help.
<?php
$from = filter_var($_POST["email1"], FILTER_SANITIZE_EMAIL);
if ( !$from ) {
die('Invalid from email address');
}
$to = "email2";
$subject = 'Test email';
//data
$msg = $_POST['response'];
mail($to, $subject, $msg, 'From: ' . $from);
echo "Mail Sent.";
?>
Use the headers option in the mail function. You can check example #2 of the php mail function here.
<?php
$from = filter_var($_POST["replyersEmail"], FILTER_SANITIZE_EMAIL);
if ( !$from ) {
die('Invalid from email address');
}
$to = "postersEmail";
$subject = 'Test email';
//data
$msg = $_POST['reply'];
mail($to, $subject, $msg, 'From: ' . $from);
echo "Mail Sent.";
?>
Please be sure to sanitize your inputs! People can abuse this, so please read this on how to do so.
Like the title says, sending a form to my email. I get no errors, but the email never comes. Here's my HTML form (I don't think you'll need anything else, but there is also some formatting and Java verification in the file).
<form method="POST" name="contactform" action="contact-form-handler.php">
<p>
<label for='name'>Your Name:</label>
<br>
<input type="text" name="name">
</p>
<p>
<label for='email'>Email Address:</label>
<br>
<input type="text" name="email">
<br>
</p>
<p>
<label for='message'>Message:</label>
<br>
<textarea name="message"></textarea>
</p>
<input type="submit" value="Submit">
<br>
</form>
And here's my PHP. Obviously I took my email out and put in EMAIL instead, but other than that this is my complete PHP file. The thank you PHP file pulls up the submitted page just fine, and I get no errors. Just no email either.
<?php
$errors = '';
$myemail = 'EMAIL#gmail.com';
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
if (!preg_match(
"/ ^[_a-z0-9-]+(\.[_a-z0-9-]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = '$myemail';
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $email_address\n Message \n $message";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
}
?>
Thanks ahead of time for any help you can provide! I can give the rest of my HTML file or my other PHP file if you need it, this is where all the real functionality lies though.
*PHP to send form data to an email i have used this code as well as its work for me .you can try *
<?PHP
$email = $_POST["emailaddress"];
$to = "you#youremail.com";
$subject = "New Email Address for Mailing List";
$headers = "From: $email\n";
$message = "A visitor to your site has sent the following email address to be added to your mailing list.\n
Email Address: $email";
$user = "$email";
$usersubject = "Thank You";
$userheaders = "From: you#youremailaddress.com\n";
$usermessage = "Thank you for subscribing to our mailing list.";
mail($to,$subject,$message,$headers);
mail($user,$usersubject,$usermessage,$userheaders);
?>
after that you can addded your futher code
Try add in top file:
error_reporting(E_ALL);
and edit your code, see:
if(mail($to,$email_subject,$email_body,$headers)){
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.html');
} else {
echo 'Error!';
}
Read this:
http://www.php.net/manual/en/function.error-reporting.php
http://www.php.net/errorfunc
http://php.net/manual/pt_BR/function.set-error-handler.php
http://www.php.net/register_shutdown_function
you have the variable $myemail as a string value after $to = Remove the parentheses and your code will work
The problem is with your From field in your $headers variable.
you can't just put any email address in there. For example: you are supposed to put an existing email address of your server that you create. Or if you want to use a gmail account in from field, you need to configure your gmail username and password with your server first before using that email.
The simplest solution is to create a new email address on your hosting server and then put that email address in your from field in $headers variable.
I've already mentioned it in details here.
The page doesn't load. I am trying to send an email from my PHP code. This is for auto-sending an email for a charity organization.
`
$name = $_POST['name'];
$message = $_POST['message'];
$message = <<<EMAIL
$name
$message
EMAIL;
$header = 'hi';
if($_POST){
mail($to, $subject, $message, $header)
$feedback = "Email Sent!";
}
?>
<!DOCTYPE html>
<body>
<p id = "feedback"><?php echo $feedback; ?></p>
<form action = "emailtest.php" method = "POST">
<label for = "name">Name: </label>
<input type = "text" name = "name" id = "name" /> <br />
<label for = "message"> Enter a Message: </label>
<textarea id = "message" name = "message" cols = "42" row = "9"></textarea> <br />
<input type = "submit" value = "Send Email">
</form>
</body>
</html>`
your first test is wrong, the $_POST variable will always be available, Also 'header' in the function does not correpond to the subject line or whatever you think it is but mail header(some info you only see when looking at the source including the id of the message, handling of the various mail servers etc...
Also please not that as is your code is vulnerable and your mailer could be used to spam others. http://www.thesitewizard.com/php/protect-script-from-email-injection.shtml
replace with something like
if(!empty($_POST)){
$name = $_POST['name'];
$message = $_POST['message'];
$message = <<<EMAIL
$name
$message
EMAIL;
mail($to, $subject, $message)
$feedback = "Email Sent!";
}
Good luck !
The functionality of your code is arbitrary.
The mail() function requires a preexisting SMTP mail server set up to be used. If you are running a WAMP stack or have not fully configured your stack, you may need to take extra step to set mail() up.
See for more info: https://www.php.net/manual/en/ref.mail.php
I recently got some help in another topic and was able to receive an email from my contact form, but all of the information save for the message text was excluded, and it was sent from "Apache". Is there any reason this might be happening?
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "______#gmail.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
$to ='______#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've received your information, thank you"
if($send_contact){
echo "We've received your contact information, thank you";
}
else {
echo "Error, please try again";
} }
?>
<form action = "../mail.php"method="POST">
<p>Name</p> <input type="text" name="name">
<p>Company</p> <input type="text" name="company">
<p>Email</p> <input type="text" name="email">
<p>Phone</p> <input type="text" name="phone">
<p>Message</p><textarea name="message" rows="4" cols="25"></textarea><br />
<input type="submit" value="Submit" name="submit">
</form>
Wrong variable name you have used.
Please change the last param of the mail call from $header to $mailHeader
$send_contact=mail($to,$subject,$message,$header);
to
$send_contact=mail($to,$subject,$message,$mailHeader);
Append all information what you need before sending. Use the below code,
$name = $_POST['name'];
$company = $_POST['company'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$messageContent = $name."\n".$company."\n".$email."\n".$phone."\n".$message."\n";
$send_contact=mail($to,$subject,$messageContent,$mailHeader);
Edit this
send_contact=mail($to,$subject,$message,$header);
to
send_contact=mail($to,$subject,$message,$mailheader);
and you can also send like this
send_contact = main($to,$subject,$formcontact,$mailheader);
if you want...and
sending mail in php is not a one-step process. mail() returns true/false, but even if it returns true, it doesn't mean the message is going to be sent. all mail() does is add the message to the queue(using sendmail or whatever you set in php.ini)
there is no reliable way to check if the message has been sent in php. you will have to look through the mail server logs.
It's my first time trying to make a contactform. And I've got a few problems
It's works, I get the email, but I don't get the name the name field with me in the email.
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<h3>Name</h3>
<input type="text" name="name">
<h3>Email Address</h3>
<input type="text" name="email">
<h3>Message</h3>
<textarea name="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form">
</form>
PHP:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $message, $name, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
$name is my problem. I've I have it in, the email comes from hostmaster#domane.com, If I delete it, everything works fine. But I wan't the name to be sent to me. How?
Or should I do it completely different?
Also, if you leave all the fields blank, the "user" doesn't get any error message, and a blank email is sent to me.
Hope you can help me. :)
Michael Berkowski is correct. What you'll need to do is add the name to your message's body (not in the sense of the input name= attribute, rather the body of the email).
Something like this:
<?php
$to = "name#domane.com";
$subject = "Contact Us";
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$headers = "From: $email";
$body = "Name: $name\r\n";
$body .= "Message: $message";
$sent = mail($to, $subject, $body, $headers) ;
if($sent)
{print "Your mail was sent successfully"; }
else
{print "One of the field are not filled as requirred"; }
?>
Revised:
HTML:
<form method="post" name="contactform" action="scripts/contact.php">
<label for="name">Name</label>
<input type="text" name="name" id="name" />
<label for="email">Email Address</label>
<input type="text" name="email" id="email" />
<label for="message">Message</label>
<textarea name="message" id="message"></textarea>
<br/><input class="submit" type="submit" value="Send Form" />
</form>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'] ;
$message = $_POST['message'] ;
$body = "Name: $name\r\n";
$body .= "Message: $message";
$to = "name#domane.com";
$from = "automailer#mydomainname.com (Website Automailer)";
$subject = "Contact Us";
$headers = "From: $from\r\n" .
"Reply-To: $email ($name)";
$sent = mail($to, $subject, $body, $headers) ;
if($sent) { echo "Your mail was sent successfully"; }
else { echo "One of the field are not filled as requirred"; }
?>
You should read the mail function documentation on php.net.
Have a look at the function signature:
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Now you're placing $name as the "$additional_headers" argument. You should pass $name and any extra relevant data in a $message argument instead.
Having that said, here's the correct code to send a message:
$sent = mail($to, $subject, "A message from $name: $message", $headers);
You should read more about how email messages are constructed. Instead of just putting a user defined message in there you probably want to specify some email headers, containing a more beautiful FROM: and the like...