Solved

PHP email troubles

Posted on 2007-04-11
17
209 Views
Last Modified: 2007-07-17
Hello -
I am still learning php.  I am trying to send 2 emails once a form is submitted.  I have commented out the section I am having problems with.  Can anyone help?

    // -- selects who to send the email to.  
    $varHRTO = "mt9839@att.com";
    $varREFTO ="m34475@att.com";

   // -- This will be the subject in the email
    $varHRSUBJECT  = "New HORIZONS Application for " . $_POST['lastname'] . " submitted on $date";
    $varREFSUBJECT = "New HORIZONS Application for " . $_POST['lastname'] . " submitted on $date";


    // To send HTML mail, the Content-type header must be set
    $HEADERS  = "Content-type: text/html\r\n";
    $HEADERS .= "From:  swbstaffing@txmail.sbc.com \r\n";

    //-- Two emails will be sent out one to the Horizons Team and one to Horizons Manager.

    //-- Start of email

    $varMESSAGE    = "<html><head></head><body>";
    $varHRMESSAGE  = $varMESSAGE;
    $varREFMESSAGE = $varMESSAGE;


    //-- Salutation of email

  //  $varHRMESSAGE .  = "A Non-Management Employee referral from the HORIZONS website has been submitted.";
 //   $varREFMESSAGE . = "Thank you for taking the time to refer this candidate!";


    //-- this is the contents of the form

  //  $varMESSAGE . = "<br /><br /><strong>Applicant Last Name:</strong> ". $_POST['lastname'] .
                      "<br /><br /><strong>Applicant First Name:</strong> ". $_POST['firstname'] .
                      "<br /><br /><strong>Applicant Middle Initial:</strong> ". $_POST['middle'] .
                      "<br /><br /><strong>Applicant PRNRS:</strong> ". $_POST['prnrs'] .
                      "<br /><br /><strong>Applicant Street Number:</strong> ". $_POST['number'] .
                      "<br /><br /><strong>Applicant Street Address:</strong> ". $_POST['street'].
                      "<br /><br /><strong>Apt Number:</strong> ". $_POST['apt'].
                      "<br /><br /><strong>Applicant City:</strong> ". $_POST['city'].
                      "<br /><br /><strong>Applicant State:</strong> " . $_POST['state'].
                      "<br /><br /><strong>Applicant Zip Code:</strong> " . $_POST['zip'] .
                      "<br /><br /><strong>Applicant Union Local:</strong> ". $_POST['localunion'] .
                      "<br /><br /><strong>Applicant NCS:</strong> ". $_POST['ncs'] .
                      "<br /><br /><strong>Applicant Work Phone:</strong> ". $_POST['workphone'] .
                      "<br /><br /><strong>Applicant Home Phone:</strong> ". $_POST['home'].
                      "<br /><br /><strong>Date of Applicant Separation:</strong> ". $_POST['separation'].
                      "<br /><br /><strong>Applicant RC Code:</strong> ". $_POST['rc'].
                      "<br /><br /><strong>Applicant Fax:</strong> ". $_POST['fax'].
                      "<br /><br /><strong>Applicant Other Contact Number:</strong> " . $_POST['other'].
                      "<br /><br /><strong>Applicant Current Job Title:</strong> " . $_POST['job'].
                      "<br /><br /><strong>Does Applicant Have a 4 Year Degree:</strong> " . $_POST['degree'] .
                      "<br /><br /><strong>Is Applicant on Disability or Leave:</strong> ". $_POST['leave'] .
                      "<br /><br /><strong>Course Objective:</strong> ". $_POST['objective'] .
                      "<br /><br /><strong>Course Start Date:</strong> ". $_POST['start_date'] .
                      "<br /><br /><strong>Course Completion Date:</strong> ". $_POST['completion'].
                      "<br /><br /><strong>Course Number:</strong> ". $_POST['course'].
                      "<br /><br /><strong>Course Units:</strong> ". $_POST['units'].
                      "<br /><br /><strong>Course Title:</strong> ". $_POST['title'].
                      "<br /><br /><strong>Course Major:</strong> " . $_POST['major'].
                      "<br /><br /><strong>Name of Provider:</strong> " . $_POST['provider'].
                      "<br /><br /><strong>Provider Address:</strong> " . $_POST['address'].
                      "<br /><br /><strong>Provider Phone Number:</strong> " . $_POST['phone'] .
                      "<br /><br /><strong>Provider fax Number:</strong> ". $_POST['providerfax'] .
                      "<br /><br /><strong>Contact Person At School:</strong> ". $_POST['contact'] .
                      "<br /><br /><strong>Tuition Fees:</strong> ". $_POST['tuition'] .
                      "<br /><br /><strong>Required Book Fees:</strong> ". $_POST['books'].
                      "<br /><br /><strong>Required Fees:</strong> ". $_POST['fees'].
                      "<br /><br /><strong>Total Required:</strong> ". $_POST['total'].
                      "<br /><br /><strong>Conditions:</strong> ". $_POST['conditions'].
                      "<br /><br /><strong>Signature:</strong> " . $_POST['signature'].
                      "<br /><br /><strong>Signature Date:</strong> " . $_POST['date'];

    $varHRMESSAGE  .= $varMESSAGE;
    $varREFMESSAGE .= $varMESSAGE;

    //-- This is only for the HR administrator

    $varHRMESSAGE .= "<br /><br />Click <a href=\"https://".$_SERVER[HTTP_HOST]."/online_detail.php?id=$id\">here </a> to view database record.";


    //-- Closing of email
    $varMESSAGE     = "<br /><br />NMSIP - Webmaster<br /></body></html>";
    $varHRMESSAGE  .= $varMESSAGE;
    $varREFMESSAGE .= $varMESSAGE;

    //-- Send email out
    mail($varHRTO,  $varHRSUBJECT,  $varHRMESSAGE,  $varHEADERS);
    mail($varREFTO, $varREFSUBJECT, $varREFMESSAGE, $varHEADERS);
0
Comment
Question by:moette88
  • 6
  • 4
  • 3
  • +1
17 Comments
 
LVL 48

Expert Comment

by:hernst42
ID: 18890459
If you wantto send HTMl-mails I suggest you use http://phpmailer.sf.net which makes the sending of mails a lot more comfortable and without a lot of errors.

example:
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();                                   // send via SMTP
$mail->Host     = "smtp1.site.com;smtp2.site.com"; // SMTP servers
$mail->From     = "from@email.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@site.com","Josh Adams");
$mail->AddAddress("ellen@site.com");               // optional name
$mail->AddReplyTo("info@site.com","Information");
0
 

Author Comment

by:moette88
ID: 18890514
My only issue is that I have to use our department server which is through my phpadmin - joomla.  I am mirroring coding that was used in a similar form.  The person is not available to ask.  Is there anyway I can get this to work?
0
 
LVL 48

Expert Comment

by:hernst42
ID: 18890845
So whats the problem excatly? Is the html not displayed when the message is received? So your headers might be incorrect. From http://php.net/mail
Maybe the headers are wrong:

$body="<em>HTML</em> formatted <strong>Message</strong";
   
$headers = "From: info@example.com \r\n";
$headers.= "Content-Type: text/html; charset=ISO-8859-1 ";
$headers .= "MIME-Version: 1.0 ";
/*notice there aren't any \r\n after the
0
 

Author Comment

by:moette88
ID: 18890993
When I "un-comment" the salutation and the contents of the form, my form no longer shows up and i get a parse error message.
0
 
LVL 50

Expert Comment

by:Steve Bink
ID: 18892216
What is the parse error message?
0
 

Author Comment

by:moette88
ID: 18892366
Parse error: parse error in /appl/nmsi/html/ssl/horizons2/online_form.php on line 403
0
 
LVL 5

Accepted Solution

by:
PatrickAdrichem earned 125 total points
ID: 18893271
ok first off all don't make your mail so loooooong

if you send a mail like

thisismyuberlongmailforyoumadeandalll!!

some servers will not exept it. Break it up using "\n" (note the "" instead of the '');

further i don't see any real problems in what you posted except that if that varmessage is multilined you only comment the first part and not the rest, put it in /*    */ just to be sure when uncommenting
and you might try adding this to each line

$varMESSAGE . =
and close each line with ;
achieves the same result.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 50

Expert Comment

by:Steve Bink
ID: 18893277
No other information in the error message?  Are you getting this from the browser output or an error log?  Paste line 403 here, please.
0
 
LVL 5

Expert Comment

by:PatrickAdrichem
ID: 18893288
Actually paste line 399 to 405 ;) might be an error in the line above. (like non closure)
0
 

Author Comment

by:moette88
ID: 18893366
Thanks - I will try.
Unfortunately I have to have a long email.  The email is suppose to show all of the information submitted on the form to the processing workgroup.
0
 
LVL 5

Expert Comment

by:PatrickAdrichem
ID: 18893437
The long e-mail is not a problem. You must however break it with line breaks ("\n") so that the email program will recieve it in multiple lines instead of just 1 huge line.
0
 

Author Comment

by:moette88
ID: 18897483
Thanks!  Do i need to put the "\n" on each line?
0
 
LVL 5

Expert Comment

by:PatrickAdrichem
ID: 18898117
I'd suggest on each line where you'd normally break it up by pressing enter.
0
 
LVL 48

Assisted Solution

by:hernst42
hernst42 earned 125 total points
ID: 18898164
The problem with you commented lines is that you put spaces between . and = which leead to parse errors:

  //  $varHRMESSAGE .  = "A Non-Management Employee referral from the HORIZONS website has been submitted.";
 //   $varREFMESSAGE . = "Thank you for taking the time to refer this candidate!";
shouldb be:

  $varHRMESSAGE .= "A Non-Management Employee referral from the HORIZONS website has been submitted.";
  $varREFMESSAGE .= "Thank you for taking the time to refer this candidate!";


0
 

Author Comment

by:moette88
ID: 18898192
Excellent!  thank you.  I wll try all suggestions this afternoon and get back to the both of you!  I'm excited.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now