Jump to content

[SOLVED] combine variables to email


herghost

Recommended Posts

Hi all,

 

I have the below:

 

<?php
require_once "Mail.php";

$from = $_GET['email'];
$to = "Contact <[email protected]>";
$subject = $_GET['subject'];
$body = $_GET['message'];
$name = $_GET['name'];


$host = "ssl://mail.stockluck.com.au";
$port = "465";
$username = "mail+stockluck.com.au";
$password = "*******";


$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject,
'Name' => $name);
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'port' => $port,
    'auth' => true,
    'username' => $username,
    'password' => $password));

$mail = $smtp->send($to, $headers, $body, $name);

if (PEAR::isError($mail)) {
  echo("<p>" . $mail->getMessage() . "</p>");
} else {

  echo("<br><br><p>Message successfully sent!<br>You will receive a reply within 24 hours, thank you for contacting Stockluck.com.au!</p>");
}
?><br>
<br>
<br>
<center>
<a href="../index.php" title="Cancel & close dialog" onclick="Modalbox.hide(); return false;">Close</a><br />

 

Which all works kinda!

 

Basically I want to attach the $name variable to the $body so I know the name of the person sending the message, at the moment it does not appear anywhere on the sent email.

 

Many Thanks

Link to comment
https://forums.phpfreaks.com/topic/180256-solved-combine-variables-to-email/
Share on other sites

Hi herghost,

 

Assign a $message variable and then create a new $body variable with the required variables combined.  For example:

 

$from = $_GET['email'];
$to = "Contact <[email protected]>";
$subject = $_GET['subject'];
$message = $_GET['message'];
$name = $_GET['name'];

$body = "$name\n\n$message\n\n";

 

Hope this helps.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.