I'm developing a website wherein the user searches for a name and results will be in a list. Then there is a link where in the user will preview an email format, like a confirmation page and at the bottom is a send button. After the button is clicked, it should send an email to that person.

My first question is should I use buttons? input type="submit"? link? Second is how do I keep passing those variables. This is the preview code:

<img src="../../img/emmlogo.jpg" style="left: 0;position: absolute; width: 75px;"/>
<body style="padding: 0 0 0 100px;position: relative;">
<?php echo date("F d, Y ");?>  <br><br>

<b><?php echo $row_Recordset1['First Name'].'&nbsp'.$row_Recordset1['Middle Initial'].'&nbsp'.$row_Recordset1['Last Name']; ?></b><br>
<?php echo $row_Recordset1 ['Position'].'<br>'.$row_Recordset1['Company Name'].'<br>'.$row_Recordset1['Corporate Address'];?><br><br>

<p>Dear <?php echo $row_Recordset1['Last Name']; ?>:</p>
//the rest of the letter goes here

How will I get to pass the variables to the email code? Should I add another page with the queries same as the preview page? or is there a way that I don't need to do that. Any help is appreciated. Thanks!

Recommended Answers

All 20 Replies

If you use a submit button (in a form), then you can add your variables as hidden inputs in that form.

I don't have a form in this code. It's more of getting data from the database.

I know, but you can output the form with hidden inputs containing the values you want to pass on submitting.

am I doing this right?

$to = "email@something.com";
$subject = "Test Mail";
$headers = "From: email@email.com \r\n" .
   "MIME-Version: 1.0\r\n" .
   "Content-Type: text/html; charset=ISO-8859-1 \r\n"; 
$message = '
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<img src="../../img/logo.jpg" style="left: 0;position: absolute; width: 75px;"/>
<body style="padding: 0 0 0 100px;position: relative;">
<?php echo date("F d, Y ");?>  <br><br>

<b> .$row_Recordset1[First Name]. .$row_Recordset1[Middle Initial]. .$row_Recordset1[Last Name]; ?></b><br>
.$row_Recordset1 [Position].<br>.$row_Recordset1[Company Name].<br>.$row_Recordset1[Corporate Address].<br><br>

<p>Dear <?php echo $row_Recordset1[Last Name]; ?>:</p>

// other parts of the letter here

</body>
</html>';

if(mail($to, $subject, $message, $headers)){
echo "An e-mail was sent to $to with the subject: $subject";
}else{
    echo "There was a problem sending the mail. Check your code and make sure that the e-mail address $to is valid";}

(i did put valid emails in the variables just repalced them for privacy)

If this is the code where the preview is submitting to, then no. $row_Recordset1 is no longer available, that's why I recommended the use of the hidden inputs.

I saved the preview file as the mail file so that the database queries are still there. is that wise?

Okay, that works too. The advantage is that a client will not see the variables passed (when using a form).

So should my code work as how you see it? I don't know how to test it. I tried to execute it and it says that the email was sent but I don't see any mail. I don't know if I should configure anything.

And can I use forms with my codes? There shouldn't be inputs in my website so I'm not sure how to do this. Thanks for the advice by the way.

From the parts you showed it appears to be working code. The only thing wrong is the building of $message. The <php in the message is not necessary (even wrong). You should use a construct like this:

$message = "<p>Dear {$row_Recordset1['Last Name']}:</p>";

Thanks. I was searching around about that too. I'm not that familiar with php yet.

I tried to insert '' 's inside the []'s but dreamweaver detects errors.

<b> {$row_Recordset1[First Name].&nbsp.$row_Recordset1[Middle Initial].&nbsp.$row_Recordset1[Last Name]}</b><br>
{$row_Recordset1 [Position].<br>.$row_Recordset1[Company Name].<br>.$row_Recordset1[Corporate Address]}<br><br>

Every single variable needs the curly brackets... you cannot enclose them around more than one.

This still returns an error :/ BTW, you're really helping me out a lot. Thanks a bunch!

<b> {$row_Recordset1['First Name']}&nbsp{$row_Recordset1['Middle Initial']}&nbsp{$row_Recordset1['Last Name']}</b><br>
{$row_Recordset1['Position']}<br>{$row_Recordset1['Company Name']}<br>{$row_Recordset1['Corporate Address']}<br><br>

<p>Dear {$row_Recordset1['Last Name']}:</p>

EDIT : Never mind I just replaced the opening tag from '' to ""

Is there any way I can test this?

Instead of emailing, just use echo to output to the screen.

I was hoping I could test if it could reach my mail. Thanks anyways. Hope I can code like you someday ^^

Oh, sorry. Just make sure the 'to' and 'from' are not the same address. The 'from' address usually has to be an account from your own domain.

Yes, yes. Thanks for reminding me.

Hi, I've already got it to mail to me but the output is

{date(F d, Y )}






Dear :

Just blank lines for the php codes and the date function doesn't work. Can you help?

The recordset is empty, how do you retrieve it?

I already got to display it. Turns out your advice about the input hidden was right. Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.