1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Calling a variable from within the mail command

Discussion in 'PHP' started by aquasonic, Jul 11, 2008.

  1. #1
    I'm using this code...
    <?php
    
    $message = "This is the message";
    
    mail($send_to, $subject,
    	'<html>
    		<body>
    			<p>
    				echo $message;
    			</p>
    		</body>
    	</html>',
    	"From: The Sender <name@domain.com>\n" .
    	"MIME-Version: 1.0\n" .
        "Content-type: text/html; charset=iso-8859-1");
    ?>
    PHP:
    But how can I make it work?

    I'm trying to send HTML emails - but I want to use information from a form to build the body of the message.

    However, because I'm in the middle of the mail command, it won't let me call the variable?

    Any ideas?
     
    aquasonic, Jul 11, 2008 IP
  2. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Probably it should be like this:

    <?php
    $message = "This is the message";
    mail($send_to, $subject,    
    '<html><body><p>' . $message . '</p></body></html>',    
    "From: The Sender <name@domain.com>\n" .    
    "MIME-Version: 1.0\n" .    
    "Content-type: text/html; charset=iso-8859-1");
    ?>
    PHP:
     
    revvi, Jul 11, 2008 IP
    aquasonic likes this.
  3. aquasonic

    aquasonic Well-Known Member

    Messages:
    90
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    115
    #3
    *red face*

    I see! I feel silly now :p


    Thank you :)
     
    aquasonic, Jul 11, 2008 IP
  4. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    You're welcome :)
     
    revvi, Jul 11, 2008 IP
  5. NatalicWolf

    NatalicWolf Peon

    Messages:
    262
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Just for future reference. the reason the first code didn't work was due to the single quotes. had you used double quotes like " then it would have showed you the value.
     
    NatalicWolf, Jul 11, 2008 IP