require_once(LIBRARY_PATH . "phpmailer.php");
require_once(CONFIG_PATH . "emailconfig.php");

class email
    public function sendMail($from,$fromname,$subject,$content,$to){
        $mail             = new PHPMailer();

        $mail->SMTPAuth   = SMTPAuth ;
        $mail->SMTPSecure = SMTPSecure;
        $mail->Host       = Host;
        $mail->Port       = Port;
        $mail->Username   = Username;
        $mail->Password   = Password;

        $mail->From       = $from;
        $mail->FromName   = $fromname;
        $mail->Subject    = $subject;
        $mail->Body       = $content;
            return false;
            return true;

The code mentioned above is used for sending mails on the website. It works fine as far as sending mail is concerned but the mail received does not have correct email address in from tag, instead it sets the email address in 'username' as 'from' address. So the 'from' address is lost and if we reply to that mail we actually send the reply to 'usename' address instead of the 'from' address.

Have no idea what is wrong with it, sets the 'fromName', 'subject', 'body' correctly. SMTPAuth, SMTPSecure, Host, Port, Username, Password are constants defined in emailconfig.php like this:







I will be really thankful if anyone could help me in this regard.

Recommended Answers

All 2 Replies

Member Avatar

Try setting the $mail->Username = $username, defining $username beforehand, maybe Username is already defined, or is some kind of system variable set up on the server.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.