I have managed to send a post from web to go. All works well except for to incorporate the senders mail.
Typing it manually there is no problem:
msg := byte(“From: sender@example.com\r\n” +
But trying to add a variable it causes error:
msg := byte("From: " + (mail) + “\r\n” +
func Send(form url.Values) {
var mail string
for key, values := range form {
for _, value := range values {
switch key {
case "mail":
mail = value
default:
fmt.Println(key, value)
}
}
}
fmt.Println(mail) <----- correct value printed
auth := smtp.PlainAuth("", "sibert@gmail.com", "password", "smtp@gmail.com")
from := (mail)
to := []string{"support@example.com"}
msg := []byte((mail) + <----------------- causing an error
"To: support@company.com\r\n" +
"Subject: subject\r\n" +
"\r\n" +
(mail)) <----- transmitted correct
err := smtp.SendMail("smtp.gmail.com:587", auth, from, to, msg)
if err != nil {
log.Fatal(err)
}
}
Any tip how to use the variable “mail” to send form values?