简体   繁体   中英

php mailer is not working

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****589@gmail.com";  
    $mail->Password = "*****02589";  

    $mail->From     = "aman***589@gmail.com";
    $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 im 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

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****589@gmail.com";  
    $mail->Password = "*****02589";  

    $mail->From     = "aman***589@gmail.com";
    $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>

在调用函数之前,先对其进行声明。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM