Jump to content

PHP mail


Digiboy

Recommended Posts

Hi guys, I am trying to send a html email via phpmail but keep receiving variables rather than data.

$to = 'me@me.com';

// subject
$subject = 'title';

// message
$message ='
<html>
<head>

</head>
<body>
  <p>How you have been effected: $effected</p>
  <p>URL: $url</p>
  <p>Company: $company</p>
   <p>Position: $position</p>
   <p>Email: $email</p>
   <p>Alternative Email: $alt_email</p>
   <p>Phone: $phone</p>
   <p>Address: $address</p>
   <p>City: $city</p>
   <p>Zip: $zip</p>
   <p>Country: $country</p>
   <p>Website: $website</p>
   <p>Signature: $signature</p>

</body>
</html>
';

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Me <no-reply@me.com>' . "\r\n";
mail($to, $subject, $message, $headers);

I have also keep changing ' to "

 

this is what i keep getting no matter what

 

How you have been effected: $effected

URL: $url

Company: $company

Position: $position

Email: $email

Alternative Email: $alt_email

Phone: $phone

Address: $address

City: $city

Zip: $zip

Country: $country

Website: $website

Signature: $signature

 

Any ideas? Thanks all in advance

Link to comment
Share on other sites

Look up the use of the heredocs structure for assembling your html/var code block. Much better than including your vars in <? ?> php tags, which is what you are missing here.

 

 

ex.

 

$message=<<<heredocs

<html>

<body>

<p>How you have been effected: $effected</p>

<p>URL: $url</p>

<p>Company: $company</p>

<p>Position: $position</p>

<p>Email: $email</p>

<p>Alternative Email: $alt_email</p>

<p>Phone: $phone</p>

<p>Address: $address</p>

<p>City: $city</p>

<p>Zip: $zip</p>

<p>Country: $country</p>

<p>Website: $website</p>

<p>Signature: $signature</p>

</body>

</html>

heredocs; // in column 1!!!!

Link to comment
Share on other sites

Use a heredoc as ginerjm suggested or change the single quotes to double quotes on your $message variable assignment. Strings in single quotes don't do variable translation where strings in double quotes do.  EX:

 

$a = 'Bob';

 

echo 'Your name is $a' . "\n";

echo "Your name is $a" . "\n";

 

Output:

Your name is $a

Your name is Bob

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.