Jump to content

Recommended Posts

I am using phpmailer to send emails from my site, the problem I have is that when I recieve an email it says its from 'adminemail@websitename.com' not 'websitename'.

 

Why is it not picking up what I pass into $mail->FromName?

<?php

// from included settings file
define ( "SITE_NAME", "websitename" );
define ( "ADMIN_EMAIL", "adminemail@websitename.com" );
define ( "DOMAIN_NAME", "www.websitename.com" );
define ( "RUN_ON_DEVELOPMENT", TRUE );
define ( "USE_SMTP", TRUE );
define ( "SMTP_PORT", "25" );
define ( "SMTP_HOST", "**************" );
define ( "SMTP_USER", "**************" );
define ( "SMTP_PASS", "**************" );
define ( "MAIL_IS_HTML", TRUE );

//send mail function
function send_email ( $subject, $to, $body )
{
    require ( "classes/class_phpmailer.php" );

    $mail = new PHPMailer();

    //do we use SMTP?
    if ( USE_SMTP ) {
            $mail->IsSMTP();
            $mail->SMTPAuth = true;
            $mail->Host = SMTP_HOST;
            $mail->Port = SMTP_PORT;
            $mail->Password = SMTP_PASS;
            $mail->Username = SMTP_USER;
    }

    $mail->From = ADMIN_EMAIL;
    $mail->FromName = SITE_NAME; // <------------------- Can't get to work
    $mail->AddAddress( $to );
    $mail->AddReplyTo ( ADMIN_EMAIL, DOMAIN_NAME );
    $mail->Subject = $subject;
    $mail->Body = $body;
    $mail->WordWrap = 100;
    $mail->IsHTML ( MAIL_IS_HTML );
    $mail->AltBody = $body;

    if ( ! $mail->Send() ) {
            if ( RUN_ON_DEVELOPMENT ) {
                echo $mail->ErrorInfo;
            }
            return FALSE;
    }
    else {
            return TRUE;
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/225841-phpmailer-fromname-issues/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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