Useing PhpMailer code inside of a function

Discussion in 'PHP' started by knight07, May 2, 2010.

  1. #1
    Hi My name is Rick

    I am trying to change the default server mail default with, PHPMailer
    with no luck, but it does work on a page by itelf, I am trying to
    replace this below, which is inside a function, and when I add the
    phpmailer code I get errors, can someone let me how to use this along
    with global variables? I could really use the help PHPMailer seems
    way better then default.

    once I get this, and understand it a bit more, I will replace the default in all
    php scripts.

    
    @mail($email, $sub, $msg, GetConfig('msgheaders')); works
    
    PHP:

    I need to find a way to use PHPMailer inside a function like above
    
    $mail = new PHPMailer(); //works by itself on another page
    
    $mail->IsSMTP(); // set mailer to use SMTP
    $mail->Host = "relay-hosting.secureserver.net"; // specify main and backup server
    $mail->SMTPAuth = false;     // turn on SMTP authentication
    $mail->Username = "username";  // SMTP username
    $mail->Password = "password"; // SMTP password
    
    $mail->From = "test1@gmail.com";
    $mail->FromName = "Testing PHPMailer";
    
    $mail->AddAddress("test@gmail.com");
    
    $mail->IsHTML(true);
    
    $mail->Subject = "Test message body";
    $mail->Body    = "Test <b>html</b>";
    $mail->AltBody = "Test Text";
    
    if(!$mail->Send())
    
    PHP:
     
    Last edited: May 2, 2010
    knight07, May 2, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Place the contents within a function, read up user defined functions.
     
    danx10, May 3, 2010 IP