I need to include the first code (which calls the e-mail from a WordPress options panel) in the second code where it says email#mail.com. I tried to include " around the code, but it doesn't seem to work. I also tried to strip slashes, but to no avail.
How I call the e-mail
<?php echo get_option('to_email'); ?>
The relevant part of my contact form:
if(!isset($hasError)) {
$emailTo = 'email#mail.com';
$subject = 'Contact Form Submission from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailTo = get_option('to_email');
You have to make sure the right files are included (wordpress config files).
Related
I am trying to send multiple variables via an email to a php page when the link is clicked on by the user, both the variables display on the email, however I am only able to pass one variable through the URL to the php page. I think this has something to do with my quotation marks
email code
$email = 'example#hotmail.co.uk';
$name = $_POST['name'];
$email_message =$message = $_POST['feedback'];
$date_added = date("y-m-d");
$message = " $email_message,
<a href='http://www.example.co.uk/email_feedback/feedback_result.php?name=$name&message=$email_message>Click HERE to Activate :)</a>";
$headers = 'From: <example.co.uk>' . "\r\n" .
'Reply-To: <example.co.uk>';
$subject ='confirm account';
mail($email, $subject, $message, $headers,
'example.co.uk');
Try changing the $message to:
$message = '$email_message,
Click HERE to Activate :)';
Your href does not have a closing "/'. And hopefully that's the only problem.
$message = $email_message. '
Click HERE to Activate :)';
this is related to contact form. i am trying to send a copy of email to user also.
so i thought to replace the same function so i repeated if(!isset($hasError)) second time and changing $emailTo = $email
and this is not working. i thing the problem might with the headers... can i write 2 different header tags ?
// to me
if(!isset($hasError)) {
$emailTo = 'myemail#website.com';
$subject = 'Submitted message from '.$name;
$sendCopy = trim($_POST['sendCopy']);
$body = "Name: $name \n\nEmail: $email \n\nComments: $comments";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
//User Copy
if(!isset($hasError)) {
$emailTo = '$email';
$subject = 'Thank you for Contacting';
$body = "Here is your copy of email which you have sent us. \n\nName: $name \n\nEmail: $email \n\nComments: $comments \n\n Thank you for your email. we will get back to your soon";
$headers = 'From: ' .' <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$UserEmailSent = true;
}
my site is hosted on name.com, and to test this I uploaded a simple file called contact.php with this at the top.
<?php
$to = '~~~~';
$subject = 'enquiry from ';
$name = $_POST['name'];
$email - $_POST['email'];
$message = $_POST['message'];
if ($_POST){
mail($to, $subject, $message, $header);
$feedback = "Sent";
}
?>
So, when I click the submit button it sends the mail. Inside a p tag I have echo $feedback, which shows up after I click submit.
The mail does not send? Anything I'm doing wrong here, or do I need to configure my cPanel in some way?
Since header is optional and is left undefined, removing it should resolve your issue.
Be aware that using the $_POST content directly into a email is a security risk for you!
THere are good email libraries that have tools to avoid abuses. (For example: ZendMail, PHPmailer)
Having said that, on your code you are missing the header and have a small mistake on $email = (not -) $_POST['email'];, you can use this:
$header = 'From: from#name.com' . "\r\n" .
'Reply-To: from#name.com' . "\r\n" .
'Content-type: text/html; charset=iso-8859-1' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
You have not set header variable which is optional, there is a typo while setting $email variable, you've use - instead of =
your updated code,
<?php
$to = 'a#a.com';
$subject = 'enquiry from ';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
if ($_POST){
mail($to, $subject, $message);
$feedback = "Sent";
}
?>
I'm using dreamhost for my mailing.
I'm having an issue with php mail function additional headers parameters.
This code works, and the email is sent:
$to = 'myemail#gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $name <**webmaster#example.com**>\r\n" .
"Reply-To: $name <**webmaster#example.com**>\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
but when I replace webmaster#example.com to the variable $email
$headers = "From: $name <**$email**>\r\n" .
"Reply-To: $name <**$email**>\r\n" .
'X-Mailer: PHP/' . phpversion();
The email doesn't get sent. I did do a print_r($_POST), and the elements are there. I also did another test where I typed the email: webmaster#example.com into the form, to see if it would send, and it did. So my question is, how do I remedy this issue, if a user types their email address into the form with another mailing extension, that mail will not get sent, but if the extension is #example.com, then the mail will get sent.
$name variable should be the full emailaddress:
"$name = " 'a name' email#whatever.com> "
$headers = "From: $from \r\n";
works on my servers. Add the leading < to the email addtress. This system won't display the string at all if I include it. If your form has different variables for the responders nam and email address you'll have to concatenate them to get $name in the right formate.
I have search for my problem and i know there is a easy fix for it but i just can't figure it out and i keep banging my head against the wall, so here goes:
i have a variable in my config file
$businessemail = "me#myemail.com";
This email changes a lot so i want to use this variable in my mail script which is this
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = '$businessemail'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
Now my question is how do i format the $businessemail in the right way so it can read and sent the message to the email in the config file
Thanks for the help.
$emailTo = $businessemail; // don't use variable in single quotes here