Announcement

Collapse
No announcement yet.

PhpMailer Difficulty

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • PhpMailer Difficulty

    A while back when eUKHost changed php mail() function I had to re-work some code quickly.

    Now i'm very novice with coding, but following one of the forum links I managed to re-do things with phpMailer. (I believe). However, I can't get the BCC part to work.

    Does the AddCC and AddBCC function not work on our servers? Or is it something I'm doing wrong.

    From Worx International Inc. I find:

    AddCC($address, $name = "")
    Adds a "Cc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

    AddBCC($address, $name = "")
    Adds a "Bcc" address. Note: this function works with the SMTP mailer on win32, not with the "mail" mailer.

    Is there a way to do BCC's?

    Thank you,
    ~devs

  • #2
    Hello Devs,

    I have not tried this code but this may help you with your coding :


    <?php
    $subject = "Your Test Email";

    $message = " $todayis [EST] \n
    Inquiry by: $visitor \n
    Their email: $visitormail \n
    Phone: $myphone \n
    Sender IP address: $MyIP \n
    Message: $notes \n
    ";

    $message = $message."This is a test message. \n";

    include("Mail.php");
    /* mail setup recipients, subject etc */

    $To=(string)$SendToEmail ;
    $bcc = "WEBMASTERS_EMAIL_ADDRESS";
    $recipients = $To.",".$bcc;
    $headers["From"] = "youremailaddress";
    $headers["To"] = $To;
    $headers["Reply-To"] = $visitormail;
    $headers["Subject"] = $subject;
    $mailmsg = $message;
    /* SMTP server name, port, user/passwd */
    $smtpinfo["host"] = "smtpservername";
    $smtpinfo["port"] = "25";
    $smtpinfo["auth"] = true;
    $smtpinfo["username"] = "Emailaddress";
    $smtpinfo["password"] = "emailpassword";
    /* Create the mail object using the Mail::factory method */
    $mail_object =& Mail::factory("smtp", $smtpinfo);
    /* Ok send mail */
    $mail_object->send($recipients, $headers, $mailmsg);

    ?>
    Regards,
    Silvester J

    Comment


    • #3
      Hello, thank-you for the reply.

      The type of coding I'm using is as below. I believe it uses a sort of PHPMailer 'plugin'/'software'.

      ob_start();
      require("class.phpmailer.php");

      $mail = new PHPMailer();

      $mail->IsSMTP(); // set mailer to use SMTP
      $mail->Host = "XXXX"; // specify main and backup server
      $mail->SMTPAuth = true; // turn on SMTP authentication
      $mail->Username = "XXXX"; // SMTP username
      $mail->Password = "XXXX"; // SMTP password

      $mail->From = "[email protected]";
      $mail->FromName = "Eye2eye Recruitment";
      $mail->AddAddress("[email protected]");

      $mail->WordWrap = 50; // set word wrap to 50 characters
      $mail->IsHTML(true); // set email format to HTML
      $mail->Subject = "Eye2eye --- Locum Registered";

      $mail->Body = "Hello this is a message";

      $mail->AltBody = "This is the body in plain text for non-HTML mail clients.";

      if(!$mail->Send())
      {
      echo "Message could not be sent. <p>";
      echo "Mailer Error: " . $mail->ErrorInfo;
      exit;
      }
      Not sure how to successfully use it to do BCC's or CC's.

      ~devs

      Comment


      • #4
        Hello ,

        Try to add AddBCC as below

        $mail->AddBCC("[email protected]");

        Example :


        ob_start();
        require("class.phpmailer.php");

        $mail = new PHPMailer();

        $mail->IsSMTP(); // set mailer to use SMTP
        $mail->Host = "XXXX"; // specify main and backup server
        $mail->SMTPAuth = true; // turn on SMTP authentication
        $mail->Username = "XXXX"; // SMTP username
        $mail->Password = "XXXX"; // SMTP password

        $mail->From = "[email protected]";
        $mail->FromName = "Eye2eye Recruitment";
        $mail->AddAddress("[email protected]");
        $mail->AddBCC("[email protected]"); // replace it with your existing email id

        $mail->WordWrap = 50; // set word wrap to 50 characters
        $mail->IsHTML(true); // set email format to HTML
        $mail->Subject = "Eye2eye --- Locum Registered";

        $mail->Body = "Hello this is a message";

        $mail->AltBody = "This is the body in plain text for non-HTML mail clients.";

        if(!$mail->Send())
        {
        echo "Message could not be sent. <p>";
        echo "Mailer Error: " . $mail->ErrorInfo;
        exit;
        }
        Thanks,
        Silvester J

        Comment


        • #5
          Still no luck

          Hello Silvester,

          Been a while but still having this same problem and it's becoming more important to fix it.

          I've tried
          $mail->AddBCC("[email protected]"); etc and it didn't help.

          I tried running the whole script twice
          for($foo=1; $foo<=2; $foo++)
          {
          if ($foo=="1")
          {$email="[email protected]";}
          if ($foo=="2")
          {$email="[email protected]";}

          MAILER FUNCTION
          $mail->AddAddress($email, "Name");
          }

          ...and that hasn't worked either.

          In the class.mailer.php file I read the following. I don't know if it's relevant or explains why it's not working for me. And even if it does, i need a way around it.

          /**
          * Adds a "Cc" address. Note: this function works
          * with the SMTP mailer on win32, not with the "mail"
          * mailer.
          * @param string $address
          * @param string $name
          * @return void
          */
          function AddCC($address, $name = "") {
          $cur = count($this->cc);
          $this->cc[$cur][0] = trim($address);
          $this->cc[$cur][1] = $name;
          }



          Please help.
          ~devsie

          Comment


          • #6
            PhpMailer Difficulty

            Hi Devsie,

            Please give a try to below code .

            $mail->AddBCC($data['my_email']);
            Note :: Replace "my_email" to the actual email address.
            Reeve.Slater
            System Administrator

            Comment


            • #7
              Thank you for your suggestion. Unfortunately, that didn't work.

              I used :
              PHP Code:
              $mail->AddBCC($data['[email protected]']); 
              And got back:

              HTML Code:
              "Message could not be sent.
              
              Mailer Error: Language string failed to load: recipients_failed" error.
              If I take out the php line you suggested, it works again, but obviously only sends to one recipient. Any further suggestions?

              Comment

              Working...
              X