Mate Keczan
Mate Keczan

Reputation: 33

Sending e-mail with SMTP using PHP

I make a customer database where I would like to add possibility to send the customers a fixed notice. First I would like to send the data to a confirming site, which also shows what data is saved in our database and requires a confirmation to send it or not. After clicking on submit it should send the e-mail.

Right now I get HTTP ERROR 500 as I proceed to the sendmail.php from e-mail.php

Unfortunately it seems like I cant give variables to the e-mail fields? I'm pretty sure my knowledge is too limited for this but I would be thankful if someone give me an advice. Thank you! :)

Here is the short form code (email.php):

<form method="POST" action="sendmail.php">
<input type="hidden" name="id" name="id" value="<?php print $id; ?>">
Are you sure to send a notification to <strong><?php print $cegnev; ?></strong>?
<input type="hidden" name="cegnev" value="<?php print $cegnev; ?>"> <br> Hidden input contains: <?php print $cegnev; ?>
<input type="hidden" name="email" value="<?php print $email; ?>"> <br> Hidden input contains: <?php print $email; ?>
<input type="hidden" name="szamla_datum" value="<?php print $szamla_datum; ?>"> <br> Hidden input contains: <?php print $szamla_datum; ?>
<input type="submit" name="elkuld">

And this is the sendmail.php:

<?php
if(isset($_POST['elkuld'])) {
  $cegnev         = $_POST['cegnev'];
  $email          = $_POST['email'];
  $szamla_datum   = $_POST['szamla_datum'];
}

$mail = new EMail;

//Enter your SMTP server (defaults to "127.0.0.1"):
$mail->Server = "host";    

//Enter your FULL email address:
$mail->Username = 'username';    

//Enter the password for your email address:
$mail->Password = 'password';

//Enter the email address you wish to send FROM (Name is an optional friendly name):
$mail->SetFrom("from email","from name");  

//Enter the email address you wish to send TO (Name is an optional friendly name):
$mail->AddTo $email;                 // #### PROBLEM

//You can add multiple recipients:
// $mail->AddTo("[email protected]");

//Enter the Subject of your message:
$mail->Subject = $cegnev;                 // #### PROBLEM

//Enter the content of your email message:
$mail->Message = $szamla_datum;                 // #### PROBLEM

//Optional extras
$mail->ContentType = "text/html";    // Defaults to "text/plain; charset=iso-8859-1"
//$mail->Headers['X-SomeHeader'] = 'abcde';    // Set some extra headers if required

echo $success = $mail->Send(); //Send the email.
?>

Upvotes: 1

Views: 235

Answers (1)

user5250856
user5250856

Reputation:

You usually get a 500 error when there is some kind of syntax error in your code, in this case,

Your line here: $mail->AddTo $email;

needs to be, assuming email is the correct variable

$mail->AddTo = $email; or $mail->AddTo($email); Whether its a variable or function in the class

Upvotes: 1

Related Questions