funcmain() { config, _ := dns.ClientConfigFromFile("/etc/resolv.conf") c := new(dns.Client)
m := new(dns.Msg) m.SetQuestion(dns.Fqdn(os.Args[1]), dns.TypeMX) m.RecursionDesired = true
r, _, err := c.Exchange(m, net.JoinHostPort(config.Servers[0], config.Port)) if r == nil { log.Fatalf("*** error: %s\n", err.Error()) }
if r.Rcode != dns.RcodeSuccess { log.Fatalf(" *** invalid answer name %s after MX query for %s\n", os.Args[1], os.Args[1]) } // Stuff must be in the answer section for _, a := range
r.Answer { fmt.Printf("%v\n", a) } }
长按识别二维码,可直达项目
9、pretty:漂亮的 Go Printf 开源三方库。示例代码:
package main
import ( "fmt"
"github.com/kr/pretty" )
funcmain() { type myType struct { a, b int } var x = []myType{{1, 2}, {3, 4}, {5, 6}} fmt.Printf("%# v", pretty.Formatter(x)) }
//Import PHPMailer classes into the global namespace //These must be at the top of your script, not inside a function usePHPMailer\PHPMailer\PHPMailer; usePHPMailer\PHPMailer\SMTP; usePHPMailer\PHPMailer\Exception;
//Instantiation and passing `true` enables exceptions $mail = new PHPMailer(true);
try { //Server settings $mail->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output $mail->isSMTP(); //Send using SMTP $mail->Host = 'smtp.example.com'; //Set the SMTP server to send through $mail->SMTPAuth = true; //Enable SMTP authentication $mail->Username = 'user@example.com'; //SMTP username $mail->Password = 'secret'; //SMTP password $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; //Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged $mail->Port = 587; //TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
//Recipients $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('joe@example.net', 'Joe User'); //Add a recipient $mail->addAddress('ellen@example.com'); //Name is optional $mail->addReplyTo('info@example.com', 'Information'); $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com');
//Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); //Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); //Optional name
//Content $mail->isHTML(true); //Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send(); echo'Message has been sent'; } catch (Exception $e) { echo"Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; }
长按识别二维码,可直达项目
18、dompdf:一个 HTML 转 PDF 的 PHP 库。示例代码:
// reference the Dompdf namespace useDompdf\Dompdf;
// instantiate and use the dompdf class $dompdf = new Dompdf(); $dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation $dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF $dompdf->render();
// Output the generated PDF to Browser $dompdf->stream();