by

golang mail(), because porting awful PHP code

golang mail(), because porting awful PHP code: 
mail.go
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/172752/golang-mail()--because-porting-awful-PHP?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
/** * simple mail func w/sendmail */ func mail(to, from, subject, message string) error { var err error cmd := exec.Command("/usr/sbin/sendmail", "-t", "-i") pipe, err := cmd.StdinPipe() if err != nil { return err } if from == "" { from = "null@void" } if err = cmd.Start(); err != nil { return err } _, err = fmt.Fprintf(pipe, "To: %s\n", to) _, err = fmt.Fprintf(pipe, "From: %s\n", from) _, err = fmt.Fprintf(pipe, "Subject: %s\n", subject) _, err = fmt.Fprintf(pipe, "\n%s\n", message) err = pipe.Close() if err != nil { return err } return cmd.Wait() }
If you want to be updated about similar snippets, Sign in and follow our Channels