Reputation: 11
Here's my phpmailer code, its not working , dont know where i am getting error.
I have to embed this code in certain script and i think for gmail port no port no 465
.
<?php
if(isset($_POST['submit'])) {
require_once('phpmailer/class.phpmailer.php');
$email=$_POST['email'];
$subject1=$_POST['subject'];
$message=$_POST['message'];
smtpmailer($email,$subject1,$message);
function smtpmailer($to,$subject,$body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "aman****[email protected]";
$mail->Password = "*****02589";
$mail->From = "aman***[email protected]";
$mail->FromName = "Cor****tions";
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
}
?><html><body>
<form method="post" action="index.php">
Email: <input name="email" id="email" type="text" /><br />
Subject:<br />
<textarea name="subject" id="subject" rows="2" cols="40"></textarea><br />
Message:<br/>
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" name="submit"/>
</form>
</body>
</html>
Can anybody help ?? where i m getting error? when i run this script its giving error-
Fatal error: Call to undefined function smtpmailer() in C:\xampp\htdocs\phpm\index.php on line 8
Upvotes: 1
Views: 1429
Reputation: 6379
You have to declare a function with its parameters, before you call it. At the moment, your program is searching for the function smtpmailer()
- but it is not even defined yet.
<?php
if(isset($_POST['submit'])) {
require_once('phpmailer/class.phpmailer.php');
$email=$_POST['email'];
$subject1=$_POST['subject'];
$message=$_POST['message'];
function smtpmailer($to,$subject,$body) {
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->Username = "aman****[email protected]";
$mail->Password = "*****02589";
$mail->From = "aman***[email protected]";
$mail->FromName = "Cor****tions";
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
smtpmailer($email,$subject1,$message);
}
?><html><body>
<form method="post" action="index.php">
Email: <input name="email" id="email" type="text" /><br />
Subject:<br />
<textarea name="subject" id="subject" rows="2" cols="40"></textarea><br />
Message:<br/>
<textarea name="message" id="message" rows="15" cols="40"></textarea><br />
<input type="submit" value="Submit" name="submit"/>
</form>
</body>
</html>
Upvotes: 2