Page 1 of 1

Email problem

Posted: Sun Apr 24, 2011 12:10 pm
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"; } 
}
}

Re: Email problem

Posted: Sun Apr 24, 2011 7:42 pm
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.

Re: Email problem

Posted: Mon Apr 25, 2011 3:08 am
by ramblin54321
The first line of your code is $body=, so why are you using $_REQUEST? I think the $_REQEST['body'] is your problem.

Re: Email problem

Posted: Mon Apr 25, 2011 10:15 pm
by todd2011
Thanks superdezign appreciate your help.

Re: Email problem

Posted: Mon Apr 25, 2011 10:53 pm
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. :)