passing multiple variables from an email to a php page via url - php

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 :)';

Related

Using PHP's mail() - name.com hosting issue

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";
}
?>

PHP mail function user can't receive the mail if I added .com.sg instead of just .com

I want to send the user an activation link after they registered an account. when I put this http://www.homeloan.com.sg in the $message I didn't receive the email, but when I remove the .sg and put http://www.homeloan.com it works. There's no error message, so I really don't know what's my mistake. Please help
here are my codes:
$id = mysql_insert_id();
$to = 'myemail#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account-> http://www.homeloan.com.sg/rates/activate?id='.$id.'';
$headers = "From: Homeloan Singapore" . "\r\n" . "Reply-To: enquiry#homeloan.com.sg";
mail($to,$subject,$message,$headers, '-f enquiry#homeloan.com.sg');
Make sure if your site have a form to fill, then fill the form correctly by assembling the input tag in the corresponded variable.
Try concatenating 'the email' to the variables ($...) with (.) or "...".
I really don't know what's my mistake
There is no mistake. I tried this code:
<?php
$id = 1;
$to = 'my_email#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account-> http://www.homeloan.com.sg/rates/activate?id='.$id;
$headers = "From: Homeloan Singapore" . "\r\n" . "Reply-To: enquiry#homeloan.com.sg";
mail($to,$subject,$message,$headers, '-f enquiry#homeloan.com.sg');
It arrived in the mailbox. Maybe, for your account it was put into spam folder?

Send email to address from form input

I have a pretty standard contact form with inputs for name, email address and phone number. As well as sending the email to the specified email address as per a standard form,
$to = 'diysoakwells#hotmail.com';
I would also like to send the email to the user using the address from the email address input from the form. I was thinking using the post variable from the email input like this would work:
$to = 'diysoakwells#hotmail.com', $email;
but no luck. Can someone point me in the right directiona and are there any security risks in using this approach? I ultimately aim to provide the user with a checkbox that if checked sends a copy of the email to themselves.
Here is a link to my form
http://www.diysoakwells.com.au/cart.php
Thankyou in advance : )
<?php
include_once("wsp_captcha.php");
if(WSP_CheckImageCode() != "OK") {
header('location:/form-rejected.php');
die();
}
$to = 'diysoakwells#hotmail.com';
$subject = 'Order Inquiry';
$jcitems = " <p><b>ORDER:</b></p><p> " . $_POST['jcitems']."<p/>" . "<p><b>Total:</b> $" . $_POST['jctotal']."</p>";
$time = date ("h:i A");
$date = date ("l, F jS, Y");
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= 'From: inquiry#diysoakwells.com' . "\r\n" .
'Reply-To: noreply#diysoakwells.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$name = $_POST['name'];
$phone = $_POST['phone'];
$emaile = $_POST['emaile'];
$textbox = $_POST['textbox'];
$text = "<html><body><p><b>Message:</b>\n$textbox</p><p>This form was submitted on Your Web Site on \n $date at\n $time</p><p><b>Customers Email Address:</b> $emaile</p><p><b>Customers Name:</b> $name </p><p><b>Customers Phone Number:</b> $phone </p></html> </body>";
$body = $text . $jcitems;
mail($to, $subject, $body, $headers);
Header('Location: ../form-accepted.php');
?>
What your doing is not what you want to do. Concatenating two strings in PHP is done with the . not the , so the correct syntax is:
$to = 'diysoakwells#hotmail.com'.", ".$emaile;
or simply
$to = "diysoakwells#hotmail.com, $emaile";
That's assuming that the code in charge of sending the email uses php's mail() function, which allows multiple emails in the $to argument. If that doesn't work, I can't be of more use without seeing the actual code.
The 'to' field on emails accepts a string, with the email address comma-separated.
$to = 'diysoakwell#hotmail.com, ' . $emaile;
should do the trick.
You should check the email address that they provide is formatted as an email address, and it would be a good idea to have a CAPTCHA to prevent automated bots from using your form as a spamming tool.
If you use php mail() function you can send copy by specifying additional headers like that:
$headers = 'Cc: '.$emaile;
mail($to, $subject, $message, $headers);

sending a email by the use of a variable

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

PHP E-Mail Form w/Options

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

Categories