I'm trying to send an e-mail using the Net::SMTP module, but it runs into an error when it gets to the dataend method. The e-mail then isn't sent. What am I doing wrong? Here is my code:
use Net::SMTP; $mailhost = 'smtp.gmail.com'; $smtp = Net::SMTP->new($mailhost) || die "Error: $!"; print "\nWho would you like the e-mail to be from?"; $from = <STDIN>; chomp $from; print "\nWho would you like to send the e-mail to?"; $to = <STDIN>; chomp $to; print "\nWhat would you like the subject of your e-mail to be?\n"; $subj = <STDIN>; chomp $subj; print "\nWhat is your message?\n"; $message = <STDIN>; chomp $message; $smtp->mail($from); $smtp->to($to); $smtp->data(); #Start the data sending #These are the headers for the e-mail. Newline character signifies end + of headers. $smtp->datasend("From: $from\n"); $smtp->datasend("To: $to\n"); $smtp->datasend("Subject: $subj\n"); $smtp->datasend("\n"); $smtp->datasend("$message"); $smtp->dataend() || print "Dataend failed: $!"; #End the data sending $smtp->quit; #Close the smtp connection

In reply to Can't get Net::SMTP to work by Metaphysical

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.