简体   繁体   中英

Add custom variable to PHP Mail script

 <?php session_start(); $_SESSION['dnevne'] = $dnevne; $email_to = "marioznik@gmail.com"; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $email_subject = "Price is: $dnevne "; $headers = "From: " . $email_from . "\\n"; $headers .= "Reply-To: " . $email_from . "\\n"; ini_set("sendmail_from", $email_from); $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from); if ($sent) { header("Location: http://www.yourdomain.com/thankyou.html"); } else { echo "There has been an error sending your comments. Please try later."; } ?> 

I add few reccomended things, but still i can't get $dnevne variable to my e-mail. Where is my mistake?

You need to learn to use sessions. Put session_start(); at the top of each page where you want to use a session variable.

Then add your $xyz variable to it as follows: $_SESSION['xyz'] = $xzy; Then that variable is accessible anywhere that you're using sessions.

As you define a variable : $dnevna = $nocna + $ukupno on your 1st page, then, I recommand putting this value in a hidden input of the form (so user can't mess with it), then access it through $dnevna = $_POST['dnevna'];

The same thing your are doing with $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"]; $name = $_POST["name"]; $email_from = $_POST["email"]; $message = $_POST["message"];

Then, you use PHP doc -> mail to make your email formatted as you need, include all needed data, and send it to you...

No need to worry about session if you're not using them before...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM