Search code examples
phpemailconcatenationmailersubject

Concatenate mail subject in PHP mailer


I have a form for users to submit their inquiry which will be sent as an email. As users are able to select their inquiry type, i wish to concatenate the inquiry type into the subject of the email.

$formname = "Website Inquiry Form";
$inquirytype = "Books";
$mail->Subject = $formname . ' - ' . $inquirytype;

When I submitted the form, I got this error, Mailer Error: SMTP Error: data not accepted.

Any advise? Thanks.


Solution

  • Read about Basic Example using SMTP
    and look at this too

    do like this

    $sub = $formname.'-'.$inquirytype;
    $mail->Subject = $sub;
    

    to add body text use

    $mail->Body = 'I'm Body text';
    

    Basic of use

    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->Host       = "mail.yourdomain.com"; // sets the SMTP server
    $mail->Port       = 25;                    // set the SMTP port for the GMAIL server
    $mail->Username   = "yourname@yourdomain"; // SMTP account username
    $mail->Password   = "yourpassword";        // SMTP account password
    
    $mail->SetFrom('name@yourdomain.com', 'First Last');
    
    $mail->AddReplyTo("name@yourdomain.com","First Last");
    
    $mail->Subject    = "PHPMailer Test Subject via smtp, basic wi