PHP sending email problem

Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default PHP sending email problem

    Hi all. I am attempting to use php to send an email that contains SESSION
    variables provided by user forms. In the body of the email, I want to use
    conditional code. So, for example, if Address2 was provided, show it in the
    body of the email. If Address2 was not provided, don't show it in the email.
    So here's the simplified version of my final form handler code (all session
    variables have already been set and are working properly): ---------------
    <?php //start the session session_start(); $date = date(' l F j, Y ');
    $email1 = 'formrecipient@somewhere.com'; $headers = 'MIME-Version: 1.0\r\n';
    $headers .= 'Content-type: text/html; charset=iso-8859-1\r\n'; $headers .=
    'From: $email\r\n'; $message1 = ' if ($_SESSION[address2]) { echo
    \'$_SESSION[address2]<br>\' ; }'; mail('$email1', 'Web Site Sign-Up',
    $message1, $headers); ?> <!--END PHP CODE--> <!--BEGIN ACTUAL PAGE CODE-->
    <html> <body> <h2>Thank you for your message.</h2> <p>We will contact you
    soon.</p> </body> </html> --------------- So I am having trouble with the
    $message1 variable which becomes the body of the recipients email. I want
    conditional code within the $message1 variable, but I'm stumped as to how to do
    it! I'm assuming it has something to do with the double quotes, but that's as
    far as I've made it! Please any help! Thanks, dlc

    dlcmpls Guest

  2. Similar Questions and Discussions

    1. Problem saving and sending .pdf files via email
      Hello, I am trying to remotely support a Mac user (OS X.2.2) with the use of forms created in Acrobat 5. She has Acrobat 6 standard installed. ...
    2. Sending an email from within ASP
      I have a form which will be processed by being sent to an ASP page. I would like the ASP page to take the data from the Request.QueryString (which I...
    3. Sending email, problem with onLoad question
      Everyone, I have a form that was created in Flash MX2004 Professional. The form is located on a layer called form and startes on frame 10. The...
    4. problem in sending email
      Dear All, I have made a .asp file in order to send email to my email@email.com: <% Set mail = Server.CreateObject ("CDONTS.NewMail") ...
    5. Problem with sending email from asp.net page using smtp
      hai i am requesting your technical support. please help me. i have been working with this for five days. the problem is relating with the...
  3. #2

    Default Re: PHP sending email problem

    dlcmpls wrote:
    > In the body of the email, I want to use
    > conditional code. So, for example, if Address2 was provided, show it in the
    > body of the email. If Address2 was not provided, don't show it in the email.
    Since you're building your message as $message1, create it like this:

    $message1 = $_SESSION['address1']."\n";
    if (isset($_SESSION['address2'])) {
    $message1 .= $_SESSION['address2']."\n";
    }

    and so on.

    Your mistake was to use echo. You don't want to display the message in a
    browser, but add it to the value of $message1.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  4. #3

    Default Re: PHP sending email problem

    Ah, I see. So basically we just build a string of text as we go correct? Makes sense to me.

    Thanks for the feedback you've helped me a lot!

    dlc
    dlcmpls Guest

  5. #4

    Default Re: PHP sending email problem

    One other question David: I'd like to use a label in the email as well,
    something like Address 1 = [Address1 variable] Email = [email variable] so
    that what the email recipient sees is well formatted and understandable.
    Suggestions?

    dlcmpls Guest

  6. #5

    Default Re: PHP sending email problem

    dlcmpls wrote:
    > One other question David: I'd like to use a label in the email as well,
    > something like Address 1 = [Address1 variable] Email = [email variable] so
    > that what the email recipient sees is well formatted and understandable.
    > Suggestions?
    Again, it's just a question of building a string:

    $message1 = 'Address 1 = '.$_SESSION['Address1']."\n";
    if (isset($_SESSION['Address2'])) {
    $message1 .= 'Address 2 = '.$_SESSION['Address2']."\n";
    }
    $message1 .= 'Comments = '.$_SESSION['Comments']."\n";

    You just build everything into one long string. It can be as long as you
    like, mail() will still send it.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    http://computerbookshelf.com
    David Powers Guest

  7. #6

    Default Re: PHP sending email problem

    Got it. Thanks David. Your help is very much appreciated!

    dlc
    dlcmpls Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139