简体   繁体   中英

PHP Mail sending, but incorrectly

my PHP mail is sending mail to me and was working 100% yesterday, but today it sends, but every field is sent as the number one. example the layout is:

Hi my name is, $name.

I would like to rent an apartment from, $apartment.

My VEI Bank account number is, $account.

Will you also check to see if our firm is purchasing from your commercial for the 10% discount? I work at, $cname.

Please contact me back via email, $email.

However, the email looks like this:

Hi my name is, 1.

I would like to rent an apartment from, 1.

My VEI Bank account number is, 1.

Will you also check to see if our firm is purchasing from your commercial for the 10% discount? I work at, 1.

Please contact me back via email, 1

if you want to look at the code the page is synergy.x10host.com/business.php

thanks in advance!

Edit

 <?php $to = 'synergy.mi@veinternational.org'; $subject = 'Commercial Purchase!'; $cname = isset($_POST['cname']); $cemail = isset($_POST['cemail']); $bank = isset($_POST['bank']); $ceo = isset($_POST['ceo']); $sqft = isset($_POST['sqft']); $message = <<<EMAIL Hello, my name is, $ceo, and I am the CEO of $cname. We would like to purchase $sqft sq ft of commercial from you for a total of $$sqft. Our Firm bank account number is, $bank. Thanks in advance and please contact us back at $cemail. EMAIL; $header = "From: $cemail"; if($_POST){ if($cname == '' || $cemail == '' || $bank == '' || $ceo == '' || $sqft == ''){ $feedback = 'Please fill out all of the fields.'; }else{ mail ( $to, $subject, $message, $header); $feedback = 'Thank you for purchasing a apartment through us!'; } } ?> <!DOCTYPE html> <html> <!--CSS Style and Title--> <head> <title>Synergy | Home</title> <link rel="stylesheet" type="text/css" href="extra/style-bus.css"> <link rel="shortcut icon" href="extra/images/synergy.png" </head> <body> <!--<div id="view-cart"> <a href="https://portal.veinternational.org/buybuttons/us06303/cart/">View Cart</a> </div>--> <div id="logonav"> <a href="index.html"><img src="extra/images/synergy.png" width="40px"></a> </div> <nav> <a href="index.html">Home</a> <a href="services.html">Services</a> <a href="contact.php">Contact Us</a> <a href="#aboutus">About Us</a> </nav> <!--Body of Page--> <div id="bus-head"> <p align="center"><font size="9">BUSINESS</font></p> </div> <div id="bus-com"> <p id="feedback"><?php echo $feedback; ?></p> <form action="?" method="post"> <ul> <li> <label for="cname">Company Name: </label> <input type="text" id="cname" name="cname" required /> </li> <li> <label for="cemail">Company Email: </label> <input type="text" name="cemail" id="cemail" required /> </li> <li> <label for="bank">Firm Bank Number: </label> <input type="text" name="bank" id="bank" required /> </li> <li> <label for="ceo">CEO Name: </label> <input type="text" name="ceo" id="ceo" required /> </li> <li> <input type="text" name="sqft" id="sqft" required /> <label for="sqft">Sq ft x $1.00 per Sq ft</label> </li> <li> <input type="submit" value="Submit" /> </li> </ul> </form> </div> <!--Footer/Extra Nav/Copyright--> <footer> <p align="center"> <small><a href="index.html">Home</a> | <a href="contact.php">Contact Us</a> | <a href="services.html">Services</a> | <a href="#">About Us</a><br/>This is an official <font color="grey"><a href="https://veinternational.org/">Virtual Enterprises International</a></font> firm website and is for educational purposes only. || 2015-2016 | Synergy, Inc.</small> </p> </footer> </body> </html> 

The reason you are getting 1 as an output is because a boolean (true) is being converted to a string. Boolean true converted to a string in PHP is 1 .

If you look at the PHP manual, isset returns a boolean. If you are wanting to check and see if the value exists before setting it, you could use something like:

$cname = isset($_POST['cname']) ? $_POST['cname'] : "Some other text";
$cemail = isset($_POST['cemail']) ? $_POST['cemail'] : "Some other text";
$bank = isset($_POST['bank']) ? $_POST['bank'] : "Some other text";
$ceo = isset($_POST['ceo']) ? $_POST['ceo'] : "Some other text";
$sqft = isset($_POST['sqft']) ? $_POST['sqft'] : "Some other text";

This way, isset checks to see if $_POST['cname'] is set. If it is set, it uses the value. Otherwise it uses some other default text that you provided.

Isset returns Boolean value. That's why you send '1' in your mail

$cname = isset($_POST['cname']);
$cemail = isset($_POST['cemail']);
$bank = isset($_POST['bank']);
$ceo = isset($_POST['ceo']);
$sqft = isset($_POST['sqft']);

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