Jump to content

Please help with sending email


lingo5

Recommended Posts

Hi again,

I have been reading on sending email with PHP and have finally done my first php mail function.

I use this to retrieve a user's pasaword and have it emailed automatically:

<?php $password = $row_user_data_RS['cliente_password']; ?>
<?php $email = $row_user_data_RS['cliente_email']; ?>
<?php mail($email, 'Your password is', $password, 'From: '.$email.''); ?>

The resulting email contains just the user password.

I would lke to know how I can add HTML code to the body of the email so that I can deliver a nicely formated email.

Thanks ll.

Link to comment
Share on other sites

OK, I heve done this now:

 

<?php
// The message
$message = "Dear client,\n your access details are:\n Usr Name:'$email'\n Password:'$password'";
$email = $row_user_data_RS['cliente_email'];
$password = $row_user_data_RS['cliente_password'];

// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);

// Send
mail($email,'Your access details', $message);
?> 
</body>
</html>
<?php
mysql_free_result($user_data_RS);
?>

An email is sent ok, but the $email and $password vars are blank. I know I'm doing something wrong here.....but what is it?

Link to comment
Share on other sites

You are putting your $message variable before you set your $email and $password variables

 

$message = "Dear client,\n your access details are:\n Usr Name:$email \n Password:$password";  <---Move this after the two below

$email = $row_user_data_RS['cliente_email'];

$password = $row_user_data_RS['cliente_password'];

Link to comment
Share on other sites

try this:

 

$message = "Dear client,\n your access details are:\n Usr Name:".$email."\n Password:".$password;

 

Variables are parsed in double quoted strings, no need to do that.

 

Swap your lines around:

// The message
$email = $row_user_data_RS['cliente_email'];
$password = $row_user_data_RS['cliente_password'];
$message = "Dear client,\n your access details are:\n Usr Name:'$email'\n Password:'$password'";

 

Variables are looked at in an ordered fashion.  So you must declare and then use, you cannot use then declare.

Link to comment
Share on other sites

OK, here's how I'm trying to redirect after succes or failure

if (mail($email, $subject, $message)) 
{
header('Location: gracias2.php');
}
else 
{
   header('Location: error.php');
}

But I get a "headers already sent" error....

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.