html5 - String / Array error on PHP form -
i'm finishing project can't seem see went wrong on php form. me correct yet i'm getting error.
warning: mail() expects parameter 4 string, array given in /customers/f/a/b/webpx.be/httpd.www/sendemail.php on line 15
my php form:
<?php $name = @trim(stripslashes($_post['name'])); $email = @trim(stripslashes($_post['email'])); $message = @trim(stripslashes($_post['message'])); $to = 'email@email.com';//replace email $headers = array(); $headers[] = "mime-version: 1.0"; $headers[] = "content-type: text/plain; charset=iso-8859-1"; $headers[] = "from: {$name} <{$from}>"; $headers[] = "reply-to: <{$from}>"; $headers[] = "subject: {$subject}"; $headers[] = "x-mailer: php/".phpversion(); mail($to, $subject, $message, $headers); die; ?> <?php if ($_post['submit']) { if (mail($to, $subject, $message, $headers)) { echo '<p>thank email! contact soon.</p>'; } else { echo '<p>oops! error occurred. try sending message again.</p>'; } } ?> <style type="text/css"> p{text-align:center;font-size:50px;background:#0091a2;margin-top:30px;padding:20px;width:500px;margin:0 auto;color:#fff} </style>
my html:
<form method="post" action="sendemail.php" onsubmit="return validation();"> <div class="row"> <div class="form-group col-md-6"> <input type="text" name="name" class="form-control" placeholder="voornaam + familienaam" required="required"> </div> <div class="form-group col-md-6"> <input type="email" name="email" class="form-control" placeholder="e-mail" required="required"> </div> <div class="form-group col-md-12"> <textarea rows="6" name="message" class="form-control" placeholder="uw boodschap ..." required="required"></textarea> </div> <div class="form-group col-md-12"> <button type="submit" class="btn btn-lg btn-dark-bg" data-loading-text="sending...">verstuur bericht</button> </div> </div> </form>
the thing think can wrong "to" in form. point me in right direction please?
thx in advance!
$headers
in array , needs string. each header should separated new line. implode()
string newline character:
$headers = array(); $headers[] = "mime-version: 1.0"; $headers[] = "content-type: text/plain; charset=iso-8859-1"; $headers[] = "from: {$name} <{$from}>"; $headers[] = "reply-to: <{$from}>"; $headers[] = "subject: {$subject}"; $headers[] = "x-mailer: php/".phpversion(); $headers = implode("\r\n", $headers); mail($to, $subject, $message, $headers);
Comments
Post a Comment