0

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!

2
Contributors
20
Replies
23
Views
4 Years
Discussion Span
Last Post by tscina
Featured Replies
  • 1

    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>"; Read More

  • 1

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

  • 1

    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. Read More

0

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

0

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

0

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)

0

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.

0

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

0

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

0

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.

1

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>";
0

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>
1

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

0

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 ""

Edited by tscina

0

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

1

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.

Edited by pritaeas

0

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?

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.