Email problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
todd2011
Forum Newbie
Posts: 9
Joined: Sat Apr 23, 2011 3:30 pm

Email problem

Post by todd2011 »

Hi,
I am using this code to sent an email.

There are 2 things happening when I get the email the body is missing in the email i get a blank email

Secondly the emails are coming slow means it takes 4 hrs to receive an email


any help is highly appreciated

todd

Code: Select all



$body = "<p><b>Personal Information</b></p>

<p>Name: $txtname  <br/>
Email: $email
</p>


<p><b>Sellers Information</b></p>
<p>Name: $txtsellersname <br/>
Address: $txtaddress 
</p>

<p><b>Property Information</b></p>

<p>Closing Date: $txtclosingdate <br/>
Sales Price: $$sales <br/>
First Lien Payoff: $$txtfirstlien <br/>
Second Lien Payoff: $$txtsecondlienoff  <br/>
Previous Years Tax Due:  $$txtprevyearstaxdue <br/>
Annual Property Taxes: $$txtannualproperttax<br/>
Real Estate Closing Fee: $$txtrealestateclosingfee<br/>
Courier/Wire Fee: $$txtcourierfee  <br/>
Tax Certificate: $$txttaxcertificates<br/>
HOA Statement Fee: $$txthoastatementfee<br/>
HOA Dues: $$txthoadues <br/>
Title Insurance: $$txttitleinsurance  <br/>
Commission: $txtcommission <br/>
Stormwater: $$txtStormwater <br/>
Buyer Paid Closing Cost: $$txtbuyerpaidclosing  <br/>
Home Warranty: $$txthomewarranty   <br/>
Repairs:  $$txtrepairs <br/>
Owners Extended Coverage:  $$ownerexcoverage<br/>
Other: $$txtother  <br/>
</p>
";


$from ="toddc@hotmail.com";
$to = $email; 
$from = $from;
$name = $txtname ;
$headers  = "From: $from\r\n"; 
$headers .= "Content-type: text/html\r\n"; 
$body = $_REQUEST['body'] ;
$subject = "Report";

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 

if($send) 
{print("<br/><br/><p>Email Confirmation has been sent to your email address.</p>");} 
else 
{print "We encountered an error sending your mail, please notify your IT Department"; } 
}
}
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Email problem

Post by superdezign »

E-mails can be tricky, particularly because you rely on an e-mail server to actually send it. They can do many different things to your e-mails and would be the cause of your e-mails taking 4 hours to send. PHP has no control over that. I recommend sending e-mail through a reliable SMTP server (i.e. your hotmail account), which can be done in PHP. However, it is tricky, especially if you don't know the ins and outs of e-mail. A forum user here (~Chris Corbyn) developed SwiftMailer which is an object-oriented approach to e-mailing and is capable of sending e-mails through SMTP servers. The documentation will walk you through setting it up.

Also, on a side note, these forums are public. Even in your code, bots can still pick up your e-mail address and start spamming it. I'd recommend censoring it. As for your code, instead of using "if ($var == '')", try using the empty() function. It's much cleaner and more complete.
ramblin54321
Forum Commoner
Posts: 32
Joined: Wed Nov 18, 2009 5:31 am

Re: Email problem

Post by ramblin54321 »

The first line of your code is $body=, so why are you using $_REQUEST? I think the $_REQEST['body'] is your problem.
todd2011
Forum Newbie
Posts: 9
Joined: Sat Apr 23, 2011 3:30 pm

Re: Email problem

Post by todd2011 »

Thanks superdezign appreciate your help.
User avatar
CrowderSoup
Forum Newbie
Posts: 18
Joined: Thu Apr 21, 2011 2:56 pm
Location: Murray, UT

Re: Email problem

Post by CrowderSoup »

You can configure your php.ini file to send from a reliable mail server, however, if you haven't done so it's most likely trying to send the email from the localhost. This often takes FOREVER and lots of times your messages will end up in the spam box of whomever is receiving them. I agree with @superdezign, try using a reliable mail server to send email.

Also, the reason your emails are coming out empty is because you're setting the value of $body at the top of your code, but then later reassign it to $_REQUEST['body']. I'm assuming $_REQUEST['body'] is empty, thus resulting in your email body being empty. Try not setting $body = $_REQUEST['body']; and see what happens. :)
Post Reply