Skip to content

Instantly share code, notes, and snippets.

@andxyz
Last active August 29, 2015 14:00
Show Gist options
  • Save andxyz/11004825 to your computer and use it in GitHub Desktop.
Save andxyz/11004825 to your computer and use it in GitHub Desktop.
going-all-php-mailer-on-a-wordpress-multisite

Development notes

Multisite is a real headache

I ended up using http://wp-cli.org to make my life easier

http://wordpress.stackexchange.com/questions/10168/what-is-the-best-way-to-load-the-wp-environment-in-a-subdomain-of-my-multisite-w/141502#141502

wp search-replace 'community.mydomain.com' 'community.mydomain.dev' --network --dry-run
wp search-replace 'sub1.mydomain.com' 'sub1.mydomain.dev' --network --dry-run
wp search-replace 'sub2.mydomain.com' 'sub2.mydomain.dev' --network --dry-run

mailer choices for php

  • github.com/swiftmailer/swiftmailer/

  • github.com/sendgrid/sendgrid-php/

Swiftmailer
<?php

    $email_formal_name = "Somebody somewhere with a computer";
    $email_user = "[email protected]";
    $to= array("[email protected]" => "A1", "[email protected]" => "A2",);

    $body .= "<br><br>";

    $body .= "<table><tbody><tr><td>";

    $body .= "<div>yourstuff</div>";

    $body .= " </td></tr>";
    $body .= "</tbody></table>";

    $office_message = $body;

    // transport
    $transport = Swift_MailTransport::newInstance();
    $mailer    = Swift_Mailer::newInstance($transport);
    // message
    $message   = Swift_Message::newInstance();
    $message->setSubject($office_subject);
    $message->setFrom(array($email_from => $email_formal_name ));
    $message->setReplyTo(array($email_user));
    $message->setBody($office_message);
    $message->addPart($office_message, 'text/html');

    // Send the message
    $failedRecipients = array();
    $numSent          = 0;
    $to               = $email_office;

    foreach ($to as $address => $name)
    {
        if (is_int($address)) {
          $message->setTo($name);
        } else {
          $message->setTo(array($address => $name));
        }

        $numSent += $mailer->send($message, $failedRecipients);
    }

    return $numSent === count($to);
?>
Sendgrid
<?php
    $sendgrid = new SendGrid('username', 'password');
    $email    = new SendGrid\Email();
    $email->addTo('[email protected]')->
           addTo('[email protected]')->
           setFrom('[email protected]')->
           setSubject('Subject goes here')->
           setText('Hello World!')->
           setHtml('<strong>Hello World!</strong>');

    $sendgrid->send($email);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment